Comparing version 0.0.7 to 0.0.8
@@ -1,40 +0,35 @@ | ||
var init = require('./db/init'); | ||
var db = require('./db/myDb'); | ||
var Order = require('./db/order'); | ||
var Customer = require('./db/customer'); | ||
var rdb = require('rdb'), | ||
resetDemo = require('./db/resetDemo'); | ||
var commit, rollback; | ||
var Customer = rdb.table('_customer'); | ||
insertDemoThenGet(); | ||
Customer.primaryColumn('cId').guid().as('id'); | ||
Customer.column('cName').string().as('name'); | ||
Customer.column('cBalance').numeric().as('balance'); | ||
Customer.column('cRegdate').date().as('registeredDate'); | ||
Customer.column('cIsActive').boolean().as('isActive'); | ||
Customer.column('cPicture').binary().as('picture'); | ||
function insertDemoThenGet() { | ||
init(runDbTest, onFailed); | ||
} | ||
var db = rdb('postgres://postgres:postgres@localhost/test'); | ||
function runDbTest() { | ||
var transaction = db.transaction(); | ||
commit = transaction.commit; | ||
rollback = transaction.rollback; | ||
resetDemo() | ||
.then(db.transaction) | ||
.then(getById) | ||
.then(printCustomer) | ||
.then(rdb.commit) | ||
.then(null, rdb.rollback) | ||
.done(onOk, onFailed); | ||
transaction.then(getById).then(printOrder).then(commit).then(null, rollback).then(onOk, onFailed).then(final); | ||
} | ||
function getById() { | ||
return Order.getById('58d52776-2866-4fbe-8072-cdf13370959b'); | ||
return Customer.getById('a0000000-0000-0000-0000-000000000000'); | ||
} | ||
function printOrder(order) { | ||
var image = order.image; | ||
console.log('id: %s, customerId: %s, status: %s, tax: %s, units: %s, regDate: %s, sum: %s, image: %s', order.id, order.customerId, order.status, order.tax, order.units, order.regDate, order.sum, order.image.toJSON()); | ||
function printCustomer(customer) { | ||
var format = 'Customer Id: %s, name: %s, Balance: %s, Registered Date: %s, Is Active: %s, Picture: %s'; | ||
var args = [format, customer.id, customer.name, customer.balance, customer.registeredDate, customer.isActive, customer.picture]; | ||
console.log.apply(null,args); | ||
} | ||
function printJSON(json) { | ||
console.log(json); | ||
} | ||
function onOk() { | ||
console.log('Success.'); | ||
} | ||
function final() { | ||
console.log('Success'); | ||
console.log('Waiting for connection pool to teardown....'); | ||
@@ -44,5 +39,4 @@ } | ||
function onFailed(err) { | ||
console.log('failed: ' + err); | ||
if (err.stack) | ||
console.log('stack: ' + err.stack); | ||
console.log('Rollback'); | ||
throw(err); | ||
} |
@@ -1,31 +0,54 @@ | ||
var init = require('./db/init'); | ||
var db = require('./db/myDb'); | ||
var Order = require('./db/order'); | ||
var Customer = require('./db/customer'); | ||
var rdb = require('rdb'), | ||
resetDemo = require('./db/resetDemo'); | ||
var commit, rollback; | ||
var Order = rdb.table('_order'); | ||
var Customer = rdb.table('_customer'); | ||
var OrderLine = rdb.table('_orderLine'); | ||
var DeliveryAddress = rdb.table('_deliveryAddress'); | ||
insertThenGet(); | ||
Order.primaryColumn('oId').guid().as('id'); | ||
Order.column('oOrderNo').string().as('orderNo'); | ||
Order.column('oCustomerId').string().as('customerId'); | ||
function insertThenGet() { | ||
init(runDbTest, onFailed); | ||
} | ||
Customer.primaryColumn('cId').guid().as('id'); | ||
Customer.column('cName').string().as('name'); | ||
function runDbTest() { | ||
var transaction = db.transaction(); | ||
commit = transaction.commit; | ||
rollback = transaction.rollback; | ||
OrderLine.primaryColumn('lId').guid().as('id'); | ||
OrderLine.column('lOrderId').guid().as('orderId'); | ||
OrderLine.column('lProduct').string().as('product'); | ||
transaction.then(getCustomers).then(printAll).then(commit).then(null, rollback).then(onOk, onFailed).then(final); | ||
} | ||
DeliveryAddress.primaryColumn('dId').guid().as('id'); | ||
DeliveryAddress.column('dOrderId').string().as('orderId'); | ||
DeliveryAddress.column('dName').string().as('name'); | ||
DeliveryAddress.column('dStreet').string().as('street'); | ||
function getCustomers() { | ||
return Customer.getMany(); | ||
var order_customer_relation = Order.join(Customer).by('customerId').as('customer'); | ||
var line_order_relation = OrderLine.join(Order).by('lOrderId').as('order'); | ||
Order.hasMany(line_order_relation).as('lines'); | ||
var deliveryAddress_order_relation = DeliveryAddress.join(Order).by('dOrderId').as('order'); | ||
Order.hasOne(deliveryAddress_order_relation).as('deliveryAddress'); | ||
var db = rdb('postgres://postgres:postgres@localhost/test'); | ||
resetDemo() | ||
.then(db.transaction) | ||
.then(getOrders) | ||
.then(toJSON) | ||
.then(print) | ||
.then(rdb.commit) | ||
.then(null, rdb.rollback) | ||
.done(onOk, onFailed); | ||
function getOrders() { | ||
return Order.getMany(); | ||
} | ||
function printAll(customers) { | ||
return customers.toJSON().then(printJSON); | ||
function toJSON(orders) { | ||
return orders.toJSON(/*strategy*/); | ||
//default strategy, expand all hasOne and hasMany relations | ||
} | ||
function printJSON(json) { | ||
function print(json) { | ||
console.log(json); | ||
@@ -35,6 +58,3 @@ } | ||
function onOk() { | ||
console.log('Success.'); | ||
} | ||
function final() { | ||
console.log('Success'); | ||
console.log('Waiting for connection pool to teardown....'); | ||
@@ -44,5 +64,4 @@ } | ||
function onFailed(err) { | ||
console.log('failed: ' + err); | ||
if (err.stack) | ||
console.log('stack: ' + err.stack); | ||
console.log('Rollback'); | ||
throw(err); | ||
} |
{ | ||
"name": "rdb-demo", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"main": "index.js", | ||
@@ -9,3 +9,3 @@ "title": "rdb-demo", | ||
"dependencies": { | ||
"rdb": "0.0.6", | ||
"rdb": "0.0.9", | ||
"promise": "5.0.0", | ||
@@ -12,0 +12,0 @@ "pg.js": "3.1.0" |
@@ -1,32 +0,54 @@ | ||
var init = require('./db/init'); | ||
var db = require('./db/myDb'); | ||
var Order = require('./db/order'); | ||
var Customer = require('./db/customer'); | ||
var rdb = require('rdb'), | ||
resetDemo = require('./db/resetDemo'); | ||
var promise = require('promise'); | ||
var commit, rollback; | ||
var Order = rdb.table('_order'); | ||
var Customer = rdb.table('_customer'); | ||
var OrderLine = rdb.table('_orderLine'); | ||
var DeliveryAddress = rdb.table('_deliveryAddress'); | ||
insertThenGet(); | ||
Order.primaryColumn('oId').guid().as('id'); | ||
Order.column('oOrderNo').string().as('orderNo'); | ||
Order.column('oCustomerId').string().as('customerId'); | ||
function insertThenGet() { | ||
init(runDbTest, onFailed); | ||
} | ||
Customer.primaryColumn('cId').guid().as('id'); | ||
Customer.column('cName').string().as('name'); | ||
function runDbTest() { | ||
var transaction = db.transaction(); | ||
commit = transaction.commit; | ||
rollback = transaction.rollback; | ||
OrderLine.primaryColumn('lId').guid().as('id'); | ||
OrderLine.column('lOrderId').string().as('orderId'); | ||
OrderLine.column('lProduct').string().as('product'); | ||
transaction.then(getCustomer).then(printCustomer).then(commit).then(null, rollback).then(onOk, onFailed).then(final); | ||
} | ||
DeliveryAddress.primaryColumn('dId').guid().as('id'); | ||
DeliveryAddress.column('dOrderId').string().as('orderId'); | ||
DeliveryAddress.column('dName').string().as('name'); | ||
DeliveryAddress.column('dStreet').string().as('street'); | ||
function getCustomer() { | ||
return Customer.getById("100"); | ||
var order_customer_relation = Order.join(Customer).by('customerId').as('customer'); | ||
var line_order_relation = OrderLine.join(Order).by('lOrderId').as('order'); | ||
Order.hasMany(line_order_relation).as('lines'); | ||
var deliveryAddress_order_relation = DeliveryAddress.join(Order).by('dOrderId').as('order'); | ||
Order.hasOne(deliveryAddress_order_relation).as('deliveryAddress'); | ||
var db = rdb('postgres://postgres:postgres@localhost/test'); | ||
resetDemo() | ||
.then(db.transaction) | ||
.then(getOrder) | ||
.then(toJSON) | ||
.then(print) | ||
.then(rdb.commit) | ||
.then(null, rdb.rollback) | ||
.done(onOk, onFailed); | ||
function getOrder() { | ||
return Order.getById('b0000000-b000-0000-0000-000000000000'); | ||
} | ||
function printCustomer(customer) { | ||
return customer.toJSON().then(printJSON); | ||
function toJSON(order) { | ||
return order.toJSON(/*strategy*/); | ||
//default strategy, expand all hasOne and hasMany relations | ||
} | ||
function printJSON(json) { | ||
function print(json) { | ||
console.log(json); | ||
@@ -36,6 +58,3 @@ } | ||
function onOk() { | ||
console.log('Success.'); | ||
} | ||
function final() { | ||
console.log('Success'); | ||
console.log('Waiting for connection pool to teardown....'); | ||
@@ -45,5 +64,4 @@ } | ||
function onFailed(err) { | ||
console.log('failed: ' + err); | ||
if (err.stack) | ||
console.log('stack: ' + err.stack); | ||
console.log('Rollback'); | ||
throw(err); | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
36920
29
950
2
1