0.5.35 • Published 9 years ago

nothinkdb v0.5.35

Weekly downloads
6
License
MIT
Repository
github
Last release
9 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

9 years ago

0.5.34

9 years ago

0.5.33

9 years ago

0.5.32

9 years ago

0.5.31

9 years ago

0.5.30

9 years ago

0.5.29

9 years ago

0.5.28

9 years ago

0.5.27

9 years ago

0.5.26

9 years ago

0.5.25

9 years ago

0.5.24

9 years ago

0.5.23

9 years ago

0.5.22

9 years ago

0.5.21

9 years ago

0.5.20

9 years ago

0.5.19

9 years ago

0.5.18

9 years ago

0.5.17

9 years ago

0.5.16

9 years ago

0.5.15

9 years ago

0.5.14

9 years ago

0.5.13

9 years ago

0.5.12

9 years ago

0.5.11

9 years ago

0.5.10

9 years ago

0.5.9

9 years ago

0.5.8

9 years ago

0.5.7

9 years ago

0.5.6

9 years ago

0.5.5

9 years ago

0.5.4

9 years ago

0.5.3

9 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.8

9 years ago

0.4.7

9 years ago

0.4.6

9 years ago

0.4.5

9 years ago

0.4.4

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago