Replies: 3 comments 1 reply
-
Oops, it is documented in the 📄 map.ts example. |
Beta Was this translation helpful? Give feedback.
-
Yes, but your example table seems to have a mix of reference and hasOne: as supplier_id is both on the my_service and my_module. |
Beta Was this translation helpful? Give feedback.
-
You will find the sql if you expand the 'Mapping tables' section. Though it is Sqlite. import map from './map';
const db = map.sqlite('demo.db');
const sql = `DROP TABLE IF EXISTS deliveryAddress; DROP TABLE IF EXISTS package; DROP TABLE IF EXISTS orderLine; DROP TABLE IF EXISTS _order; DROP TABLE IF EXISTS customer;
CREATE TABLE customer (
id INTEGER PRIMARY KEY,
name TEXT,
balance NUMERIC,
isActive INTEGER
);
CREATE TABLE _order (
id INTEGER PRIMARY KEY,
orderDate TEXT,
customerId INTEGER REFERENCES customer
);
CREATE TABLE orderLine (
id INTEGER PRIMARY KEY,
orderId INTEGER REFERENCES _order,
product TEXT,
amount NUMERIC(10,2)
);
CREATE TABLE package (
packageId INTEGER PRIMARY KEY,
lineId INTEGER REFERENCES orderLine,
sscc TEXT
);
CREATE TABLE deliveryAddress (
id INTEGER PRIMARY KEY,
orderId INTEGER REFERENCES _order,
name TEXT,
street TEXT,
postalCode TEXT,
postalPlace TEXT,
countryCode TEXT
)
`;
async function init() {
const statements = sql.split(';');
for (let i = 0; i < statements.length; i++) {
await db.query(statements[i]);
}
}
export default init; |
Beta Was this translation helpful? Give feedback.
-
Hello!
First of all, thank you a lot for this fp ORM.
I would like to know how to map using References with Orange ORM?
Is it okay to use the
by
function to reproduce it?Something like:
Beta Was this translation helpful? Give feedback.
All reactions