-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (24 loc) · 790 Bytes
/
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
const { Model } = require('objection');
const Knex = require('knex');
const hashid = require('objection-hashid');
const config = require('./knexfile');
const knex = Knex(config);
Model.knex(knex);
class BaseModel extends hashid(Model) {
static hashIdSalt = 'asalt';
static hashIdMinLength = 8;
}
class Person extends BaseModel {
static tableName = 'persons';
}
class Pet extends BaseModel {
static tableName = 'pets';
static hashedFields = ['person_id'];
}
async function main() {
const jake = await Person.query().insert({ name: 'Jake' });
console.log('jake', jake);
console.log('jake.hashid', jake.hashid);
const pixel = await Pet.query().insert({ name: 'Pixel', person_id: jake.hashId });
}
main().catch(err => console.error(err)).finally(() => knex.destroy());