const TodoEntity = defineEntity(TodoSchema)
.belongsTo(t => t.author, l => l.userId, r => r.id);
const UserEntity = defineEntity(UserSchema);
const db = createDb(knex, { todos: TodoEntity, users: UserEntity });
const todo = await db.todos
.where(t => t.id, '=', 42)
.include(t => t.author)
.first();
await db.transaction(async dbTrx => {
const u = await dbTrx.users.insert({ email: 'a@b.c', role: 'user', authProvider: 'local', createdAt: new Date() });
await dbTrx.todos.insert({ title: 'Hi', userId: u.id, completed: false, createdAt: new Date(), updatedAt: new Date() });
});
Create a typed database context.
Optionalopts: { tracking?: false }const TodoEntity = defineEntity(TodoSchema)
.belongsTo(t => t.author, l => l.userId, r => r.id);
const UserEntity = defineEntity(UserSchema);
const db = createDb(knex, { todos: TodoEntity, users: UserEntity });
const todo = await db.todos
.where(t => t.id, '=', 42)
.include(t => t.author)
.first();
await db.transaction(async dbTrx => {
const u = await dbTrx.users.insert({ email: 'a@b.c', role: 'user', authProvider: 'local', createdAt: new Date() });
await dbTrx.todos.insert({ title: 'Hi', userId: u.id, completed: false, createdAt: new Date(), updatedAt: new Date() });
});
Create a typed database context.