UNPKG

rdb-demo

Version:
31 lines (25 loc) 1.04 kB
let rdb = require('rdb'), resetDemo = require('../db/resetDemo'); let Order = rdb.table('_order'); let DeliveryAddress = rdb.table('_deliveryAddress'); Order.primaryColumn('oId').guid().as('id'); Order.column('oOrderNo').string().as('orderNo'); DeliveryAddress.primaryColumn('dId').guid().as('id'); DeliveryAddress.column('dOrderId').string().as('orderId'); DeliveryAddress.column('dName').string().as('name'); DeliveryAddress.column('dStreet').string().as('street'); let deliveryAddress_order_relation = DeliveryAddress.join(Order).by('dOrderId').as('order'); Order.hasOne(deliveryAddress_order_relation).as('deliveryAddress'); let db = rdb('postgres://rdb:rdb@localhost/rdbdemo'); module.exports = async function() { try { await resetDemo(); await db.transaction(async () => { let filter = Order.deliveryAddress.exists(); let orders = await Order.getMany(filter); console.log(await orders.toDto()); }); } catch (e) { console.log(e.stack); } }();