Opinionated completely asynchronous ODM for RethinkDB. Provides generic CRUD functionality out of the box. Fill free to use Promises or Async Await with try catch. All examples are with Async Await.
yarn add rectifyjs
import Rectify from "rectifyjs";
let DB: Rectify;
(async function () {
try {
DB = await Rectify.build({
db: process.env.RETHINK_DB_NAME,
host: process.env.RETHINK_DB_HOST,
port: process.env.RETHINK_DB_PORT,
tableNames: ["users", "posts", "comments"],
});
} catch (e) {
console.error(e);
}
})();Instantiates a new instance of Rectify
| Param | Default Values | Type |
|---|---|---|
| db | "test" | string |
| host | "localhost" | string |
| port | 28015 | number |
| tableNames | [] | string[] |
Methods for all CRUD Operations
Create:
createcreateWithId
Read:
getAllgetWithIdgetWithQuery
Update:
updateWithId
Delete:
deleteWithIddeleteAll
Create methods always return id of newly created item.
(async function () {
const id = await DB.tables.users.create({
name: "John",
age: 37,
isMarried: true,
});
const id = await DB.tables.users.createWithId("random-id", {
name: "Jill",
age: 23,
isMarried: false,
});
})();(async function () {
const users = await DB.tables.users.getAll();
const user = await DB.tables.users.getWithId("random-id");
const users = await DB.tables.users.getWithQuery(
"field",
RectifyOperator.EQ,
"value"
);
})();(async function () {
const id = await DB.tables.users.updateWithId("random-id", {
name: "John",
age: 37,
isMarried: true,
});
})();(async function () {
await DB.tables.users.deleteWithId('user-id');
await DB.tables.users.deleteAll();
})();