-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INSERT ON Conflict resolution #42
- Loading branch information
Showing
7 changed files
with
168 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const rdb = require('../src/index'); | ||
|
||
const nameSchema = { | ||
type: 'string', | ||
}; | ||
|
||
|
||
function validateName(value) { | ||
if (value && value.length > 10) | ||
throw new Error('Length cannot exceed 10 characters'); | ||
} | ||
|
||
function truthy(value) { | ||
if (!value) | ||
throw new Error('Name must be set'); | ||
} | ||
|
||
const map = rdb.map(x => ({ | ||
customer: x.table('customer').map(({ column }) => ({ | ||
id: column('id').numeric().primary().notNullExceptInsert(), | ||
name: column('name').string().validate(validateName).validate(truthy).JSONSchema(nameSchema), | ||
balance: column('balance').numeric(), | ||
isActive: column('isActive').boolean(), | ||
})), | ||
|
||
package: x.table('package').map(({ column }) => ({ | ||
id: column('packageId').numeric().primary().notNullExceptInsert(), | ||
lineId: column('lineId').numeric().notNullExceptInsert(), | ||
sscc: column('sscc').string() | ||
})), | ||
|
||
order: x.table('_order').map(({ column }) => ({ | ||
id: column('id').numeric().primary().notNullExceptInsert(), | ||
orderDate: column('orderDate').date().notNull(), | ||
customerId: column('customerId').numeric().notNullExceptInsert(), | ||
})), | ||
|
||
orderLine: x.table('orderLine').map(({ column }) => ({ | ||
id: column('id').numeric().primary().notNullExceptInsert(), | ||
orderId: column('orderId').numeric(), | ||
product: column('product').string(), | ||
})), | ||
|
||
deliveryAddress: x.table('deliveryAddress').map(({ column }) => ({ | ||
id: column('id').numeric().primary().notNullExceptInsert(), | ||
orderId: column('orderId').numeric(), | ||
name: column('name').string(), | ||
street: column('street').string(), | ||
postalCode: column('postalCode').string(), | ||
postalPlace: column('postalPlace').string(), | ||
countryCode: column('countryCode').string(), | ||
})) | ||
})).map(x => ({ | ||
orderLine: x.orderLine.map(({ hasMany }) => ({ | ||
packages: hasMany(x.package).by('lineId') | ||
})) | ||
})).map(x => ({ | ||
order: x.order.map(({ hasOne, hasMany, references }) => ({ | ||
customer: references(x.customer).by('customerId'), | ||
deliveryAddress: hasOne(x.deliveryAddress).by('orderId'), | ||
lines: hasMany(x.orderLine).by('orderId') | ||
})) | ||
|
||
})); | ||
|
||
module.exports = map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters