https://github.com/mastilver/nosqwal
NoSQL Database interface
https://github.com/mastilver/nosqwal
Last synced: 5 months ago
JSON representation
NoSQL Database interface
- Host: GitHub
- URL: https://github.com/mastilver/nosqwal
- Owner: mastilver
- License: mit
- Created: 2016-01-27T10:57:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-05T19:15:29.000Z (about 9 years ago)
- Last Synced: 2025-09-22T11:19:19.095Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# nosqwal [](https://travis-ci.org/mastilver/nosqwal) [](https://coveralls.io/github/mastilver/nosqwal?branch=master)
> Low level ODM library
## Install
```
$ npm install --save nosqwal-memory
```
## Adapters
- [In memory](https://www.npmjs.com/package/nosqwal-memory)
- [Couchbase](https://github.com/mastilver/nosqwal-couchbase)
- [OrientDb](https://github.com/mastilver/nosqwal-orientdb)
## Usage
```js
const nosqwal = require('nosqwal-memory');
const db = nosqwal();
const userCollection = db.defineCollection('user');
userCollection.create({
username: 'Alice',
password: '*****'
})
.then(alice => {
return userCollection.query(
where: {
username: {
$eq: 'Alice'
}
},
limit: 1
});
})
.then(users => {
console.log(users[0].username);
//=> 'Alice'
});
```
## API
### const db = nosqwal([options])
#### options
Type: `Object`
Default: `{}`
Options needed to customize your nosqwal instance, they are different for each nosqwal adapters
### const collection = db.defineCollection(collectionName)
#### collectionName
Type: `string`
Name of the collection
### collection.create(document);
Retuns a Promise that resolve to the newly created document
The property `id` is added to that document
#### document
Type: `Object`
The document that will be created
### collection.get(documentId)
Returns a Promise that resolve to the requested document
#### documentId
The unique identifier of the document to retrieve
### collection.update(document)
Returns a Promise that resolve to the updated document
Type: `string`
#### document
The object that will replace the current document stored in the database
##### document.id
The unique identifier of the document to update
### collection.query({ where, orderBy, limit, offset })
Returns a Promise that resolve in an array of the requested document
#### where
Type: `Object`
##### where[key] = whereClause
###### key
Type: `string`
Key or path of field to match
Key could also be one of the following for more complex query:
- `$not`
- `$and`
- `$or`
###### whereClause
Type: `object`
WhereClause define the where clause for a field. WhereClause can also be the same as `where` for more complex query.
###### whereClause[operator] = value
Operator can be:
| operator | description | `value` type | data type |
|----------|-------------|--------------|-----------|
| `$eq` | equal to | `any` | `any` |
| `$ne` | not equal to | `any` | `any` |
| `$gt` | gretter than | `string`,`number`,`Date` | `string`,`number`,`Date` |
| `$gte` | gretter or equal to | `string`,`number`,`Date` | `string`,`number`,`Date` |
| `$lt` | lower than | `string`,`number`,`Date` | `string`,`number`,`Date` |
| `$lte` | lower or equal to | `string`,`number`,`Date` | `string`,`number`,`Date` |
| `$contains` | string/array contains | `any` | `string`, `Array` |
| `$in` | is in array | `Array` | `any` |
#### orderBy
Type: `array`
Default: []
##### orderBy[][0]
Type: `string`
Path / key to order
##### orderBy[][1]
Is ascending
Type: `bool`
Default: `true`
#### limit
Type: `number`
Default: `undefined`
How many documents will be returned
#### offset
Type: `number`
Default: `0`
## License
MIT © [Thomas Sileghem](http://mastilver.com)