-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (31 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const Customer = require('./models/customer');
const Order = require('./models/order');
const knex = require('./util/database');
async function main() {
// Delete all persons from the db.
await Customer.query().delete();
await Order.query().delete();
// Insert one row to the database.
const customer = await Customer.query().insert({
name: 'Rachel Green',
email: 'rg@gmail.com',
});
// Read all rows from the db.
const customerRead = await Customer.query();
console.log(customerRead);
const order = await Customer.relatedQuery('order')
.for(customer.id)
.insert({ total: 55 });
console.log(order);
const orderTotal = await Order.query()
.select('total')
.where('customer_id', '=', customer.id)
.orderBy('total');
console.log(orderTotal);
}
main()
.then(() => knex.destroy())
.catch((err) => {
console.error(err);
return knex.destroy();
});