Comparing version 0.2.0 to 0.2.1
import r from 'rethinkdb'; | ||
import Joi from 'joi'; | ||
import { Table } from '../'; | ||
import { Table, schema } from '../'; | ||
@@ -8,4 +8,5 @@ const userTable = new Table({ | ||
schema: () => ({ | ||
...Table.schema, | ||
id: schema.id, | ||
name: Joi.string().required(), | ||
isPremium: Joi.boolean().default(false), | ||
}), | ||
@@ -18,16 +19,21 @@ }); | ||
// sycn table with rethinkdb server | ||
// sync table | ||
await userTable.sync(connection); | ||
// create user data (locally) | ||
const foo = userTable.create({ name: 'foo' }); | ||
const bar = userTable.create({ name: 'bar' }); | ||
// delete all users | ||
await userTable.query().delete().run(connection); | ||
// insert user data to rethinkdb server | ||
await userTable.insert([foo, bar]).run(connection); | ||
// create user data | ||
const normalUser = userTable.create({ name: 'user1' }); | ||
const premiumUser = userTable.create({ name: 'user2', isPremium: true }); | ||
// getAll users with array (default is cursor) | ||
// insert user data into rethinkdb server | ||
await userTable.insert([ | ||
normalUser, | ||
premiumUser, | ||
]).run(connection); | ||
// getAll users | ||
const users = await userTable.query().coerceTo('array').run(connection); | ||
// ... do something with users. | ||
console.log(users); | ||
@@ -34,0 +40,0 @@ |
{ | ||
"name": "nothinkdb", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Functional toolkit for rethinkdb", | ||
@@ -5,0 +5,0 @@ "main": "lib/nothinkdb.js", |
@@ -1,29 +0,69 @@ | ||
# What? | ||
[![npm version](https://badge.fury.io/js/nothinkdb.svg)](https://badge.fury.io/js/nothinkdb) | ||
# Nothinkdb | ||
Functional toolkit for [rethinkdb](https://www.rethinkdb.com/api/javascript/). | ||
# Feature | ||
- handle schema validation with [joi](https://github.com/hapijs/joi). | ||
- handle default fields like `id`, `createdAt`, `updatedAt`. | ||
- fully customizable 1-n, 1-1, n-1, n-m relations. (create, remove, join). | ||
- ensure table, secondary index. | ||
- many useful query generator. | ||
- __table__ | ||
- schema: handle schema with [joi](https://github.com/hapijs/joi) | ||
- validate | ||
- generate default value | ||
- __relations__ | ||
- types | ||
- one-to-one: hasOne | ||
- one-to-many: hasMany | ||
- many-to-one: belongsTo | ||
- many-to-many: belongsToMany | ||
- join | ||
- create | ||
- remove | ||
- __sync__: create table, secondary index... | ||
- __query__: handle table data with rethinkdb. | ||
## Install | ||
# API | ||
```bash | ||
npm install -S nothinkdb | ||
``` | ||
See the [API Reference](https://github.com/ironhee/nothinkdb/blob/master/API.md). | ||
## Example | ||
# Example | ||
```js | ||
import r from 'rethinkdb'; | ||
import Joi from 'joi'; | ||
import { Table, schema } from 'nothinkdb'; | ||
See the [Examples](https://github.com/ironhee/nothinkdb/tree/master/examples) | ||
const userTable = new Table({ | ||
table: 'user', | ||
schema: () => ({ | ||
id: schema.id, | ||
name: Joi.string().required(), | ||
isPremium: Joi.boolean().default(false), | ||
}), | ||
}); | ||
async function run() { | ||
// open rethinkdb connection | ||
const connection = await r.connect({ db: 'test' }); | ||
// sync table | ||
await userTable.sync(connection); | ||
// create user data | ||
const normalUser = userTable.create({ name: 'user1' }); | ||
const premiumUser = userTable.create({ name: 'user2', isPremium: true }); | ||
// insert user data into rethinkdb server | ||
await userTable.insert([ | ||
normalUser, | ||
premiumUser, | ||
]).run(connection); | ||
// getAll users | ||
const users = await userTable.query().coerceTo('array').run(connection); | ||
console.log(users); | ||
// close rethinkdb connection | ||
await connection.close(); | ||
} | ||
run(); | ||
``` | ||
If you want to see more examples, See the [Examples](https://github.com/ironhee/nothinkdb/tree/master/examples) | ||
## API | ||
See the [API Reference](https://github.com/ironhee/nothinkdb/blob/master/API.md). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47266
1042
70