0.5.35 • Published 8 years ago

nothinkdb v0.5.35

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

npm version Build Status

Nothinkdb

Functional toolkit for rethinkdb.

Currently, Compitable with rethinkdb 2.2.x

  • define declarative table schema.
  • handle schema validation with joi.
  • handle default fields like id, createdAt, updatedAt.
  • ensure table, secondary index.
  • ensure unique field.
  • fully customizable 1-n, 1-1, n-1, n-m relations.
  • define, create, remove, check, query, join relations.
  • many useful query generator.
  • easily implement graphql server with nothinkdb-graphql

Install

npm install -S nothinkdb

Example

import Joi from 'joi';
import r from 'rethinkdb';
import { Table, schema } from 'nothinkdb';

const userTable = new Table({
  tableName: '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);
  await followingTable.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

API

See the API Reference.

Related Links

0.5.35

8 years ago

0.5.34

8 years ago

0.5.33

8 years ago

0.5.32

8 years ago

0.5.31

8 years ago

0.5.30

8 years ago

0.5.29

8 years ago

0.5.28

8 years ago

0.5.27

8 years ago

0.5.26

8 years ago

0.5.25

8 years ago

0.5.24

8 years ago

0.5.23

8 years ago

0.5.22

8 years ago

0.5.21

8 years ago

0.5.20

8 years ago

0.5.19

8 years ago

0.5.18

8 years ago

0.5.17

8 years ago

0.5.16

8 years ago

0.5.15

8 years ago

0.5.14

8 years ago

0.5.13

8 years ago

0.5.12

8 years ago

0.5.11

8 years ago

0.5.10

8 years ago

0.5.9

8 years ago

0.5.8

8 years ago

0.5.7

8 years ago

0.5.6

8 years ago

0.5.5

8 years ago

0.5.4

8 years ago

0.5.3

8 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.8

8 years ago

0.4.7

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago