74 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-06-17 16:17:15 +02:00
'use strict';
const util = require('util');
2021-06-17 16:17:15 +02:00
2021-06-28 21:37:44 +02:00
const { Database } = require('../lib/index');
2021-06-24 18:28:36 +02:00
const models = require('./models');
const connections = require('./connections');
2021-06-28 21:37:44 +02:00
async function main(connection) {
2021-06-28 12:34:29 +02:00
const orm = await Database.init({
2021-06-28 21:37:44 +02:00
connection,
2021-06-24 18:28:36 +02:00
models: Database.transformContentTypes(models),
});
2021-06-17 16:17:15 +02:00
2021-06-24 18:28:36 +02:00
try {
// await orm.schema.drop();
// await orm.schema.create();
await orm.schema.reset();
2021-06-24 18:28:36 +02:00
2021-07-26 19:40:30 +02:00
let res;
2021-07-08 18:15:32 +02:00
2021-07-26 19:40:30 +02:00
const c1 = await orm.query('comment').create({
data: {
title: 'coucou',
},
});
2021-07-26 19:40:30 +02:00
const c2 = await orm.query('video-comment').create({
data: {
2021-07-26 19:40:30 +02:00
title: 'coucou',
},
});
2021-07-26 19:40:30 +02:00
res = await orm.query('article').create({
data: {
dz: [
{
__type: 'comment',
id: c1.id,
},
{
__type: 'video-comment',
id: c2.id,
},
],
},
2021-07-26 19:40:30 +02:00
populate: {
dz: true,
},
});
2021-07-26 19:40:30 +02:00
log(res);
res = await orm.query('article').findMany({
populate: {
dz: true,
},
});
log(res);
2021-07-01 13:52:01 +02:00
// await tests(orm);
2021-06-24 18:28:36 +02:00
} finally {
orm.destroy();
}
}
function log(res) {
console.log(util.inspect(res, null, null, true));
}
2021-06-28 21:37:44 +02:00
main(connections.sqlite);