# @tiny-apps/nosql-db

> Tiny no-sql database

Latest version **0.0.4** (published 2022-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tiny-apps/nosql-db
pnpm add @tiny-apps/nosql-db
yarn add @tiny-apps/nosql-db
bun add @tiny-apps/nosql-db
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2022-04-05 |
| First published | 2022-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 80.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | xavikortes |
| Maintainers | xavikortes |
| Keywords | mongo, mongodb, tiny, nosql, database, db |

## Links

- npm: https://www.npmjs.com/package/@tiny-apps/nosql-db
- Repository: https://github.com/with-tiny/nosql-db
- Homepage: https://github.com/with-tiny/nosql-db#readme
- Issues: https://github.com/with-tiny/nosql-db/issues
- npm.io page: https://npm.io/package/@tiny-apps/nosql-db

## Dependencies (1)

- [nanoid](https://npm.io/package/nanoid.md) ^3.3.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2022-04-05
- 0.0.3 — 2022-04-03
- 0.0.2 — 2022-04-02
- 0.0.1 — 2022-04-02

## README

<div align="center">
  <h1>tiny-nosql-db 🤏💾</h1>
  <p>Tiny NoSql Database for little projects</p>
  <hr />
  <p>
    <img src='https://img.shields.io/npm/v/@tiny-apps/nosql-db.svg?style=flat-square' alt='version-badge'>
    <img src='https://img.shields.io/npm/l/@tiny-apps/nosql-db.svg?style=flat-square' alt='license-badge'>
  </p>
</div>

## Installation

Go to the root of your project and run
```
npm install -D @tiny-apps/nosql-db
```

And it to .gitignore
```
node_modules/
dist/
...
.storage/
```

## Usage

Import the server and start it.
```js
import nosqlServer from '@tiny-apps/nosql-server'

const server = nosqlServer()
```

Then set the database to use
```js
const db = server.use('test_database')
```

And just choose a collection and run any method on it
```js
db.test_people.insertOne({
  name: 'John',
  surname: 'Dow',
  age: 31,
})
```
Here is the complete example

```js
import nosqlServer from '@tiny-apps/nosql-server'

const server = nosqlServer()
const db = server.use('test_database')

db.test_people.insertOne({
  name: 'John',
  surname: 'Dow',
  age: 31,
})
// returns { ok: true, _id: xxx, count: 1 }

db.test_people.find({
  age: 31,
})
// returns [{ _id: xxx, name: 'John', surname: 'Dow', age: 31 }]
```

## Custom folder or name

You can change the default storage folder or name by passing them as named arguments in server creation

```js
import nosqlServer from '@tiny-apps/nosql-server'

const server = nosqlServer({
  name: 'Main Db Server',
  path: './custom-storage'
})
```

## Special operators

Special operators are reserved keys that allow build complex queries. All special operators starts with and underscore.

```js
const discountedUsers = db.test_people.find({
  _or: [
    { age: { _lt: 18 } },
    { age: { _gt: 65 } },
  ]
})
```

### Available operators

#### Comparation operators
- _eq. Filter where field is equal to value
- _neq. Filter where field is not equal to value
- _gt. Filter where field greater than value
- _gte. Filter where field greater or equal than value
- _lt. Filter where field lower than value
- _lte. Filter where field lower or equal than value
- _in. Filter where field is in value array
- _nin. Filter where field is not in value array

#### Logical operators
- _and. Filter where all condition array items matches
- _or. Filter where at leats one condition array item matches
- _nor. Filter where none condition array item matches
- _not. Filter where condition not matches

## Available methods

### Server
- use(_dbName). Sets the current database to _dbName
- listDatabases(). Return an array of all databases of the server
- createDatabase(_name). Creates a database (implicit in use())
- dropDatabase(_name). Deletes a database

### Database
- collection(_name) o db[_name]. Sets the current collection to _name
- listCollections(). Return an array of all collections of the database
- createCollection(_name). Creates a collection (implicit in db.[_name])
- dropCollection(_name). Deletes a collection

### Collection
- find(_filter). Query the collection and returns matched records
- findOne(_filter). Returns a record if only one matches
- count(_filter). Count the records mathed on a query
- distinct(_field). Return distinct values of _field in a collection
- insertOne(_record). Insert a record
- insertMany(_recordList). Insert a list of records
- updateOne(_filter, _record). Update a record if only one matches
- updateMany(_filter, _record). Update records that matches
- deleteOne(_filter). Delete a record if only one matches
- deleteMany(_filter). Delete records that matches

## Next Features

- More query and update special operators

---
_Source: https://npm.io/package/@tiny-apps/nosql-db · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
