@@ -80,14 +80,10 @@ const db = new ShoppingContext();
8080const q = db .customers
8181 // set parameters
8282 .where ({ orderID },
83- // access parameters
84- (p ) =>
85- // following expression
86- // be converted to SQL
87- (customer ) => customer .orders .some (
83+ (customer , /* Parameter */ p ) => customer .orders .some (
8884 // joins/exists will be set
8985 // based on relations declared
90- (order ) => order .orderID === p .orderID );
86+ (order ) => order .orderID === p .orderID )) ;
9187const customer = await q .first ();
9288```
9389Above expression will result in following filter expression
@@ -109,8 +105,7 @@ Query with Like operator
109105// / Sql functions
110106const userName = ` akash% ` ;
111107const q = db .orders .where ({ userName },
112- (params ) =>
113- (order ) =>
108+ (order , params ) =>
114109 Sql .text .like (
115110 order .customer .userName ,
116111 params .userName
@@ -180,7 +175,7 @@ class Product {
180175 @Column ({ default : () => " " })
181176 productCode: string ;
182177
183- // You can specifiy computed expression
178+ // You can specify computed expression
184179 // that will be converted to equivalent SQL
185180 // for target provider.
186181 @Column ({
@@ -213,7 +208,7 @@ class OrderItem {
213208 @RelateTo (Product , {
214209 property : (orderItem ) => orderItem .product ,
215210 inverseProperty : (product ) => product .orderItems ,
216- foreignKeyContraint : {
211+ foreignKeyConstraint : {
217212 name: " FK_OrderItems_ProductID" ,
218213 onDelete: " restrict"
219214 }
@@ -224,7 +219,7 @@ class OrderItem {
224219 @RelateTo (Order , {
225220 property : (orderItem ) => orderItem .order ,
226221 inverseProperty : (order ) => order .orderItems ,
227- foreignKeyContraint : {
222+ foreignKeyConstraint : {
228223 name: " FK_OrderItems_OrderID" ,
229224 onDelete: " delete"
230225 }
@@ -273,8 +268,7 @@ using helper functions to convert before comparison.
273268``` typescript
274269 const q = db .customers
275270 .where ({ orderID },
276- (p ) =>
277- (x ) => x .orders .some (
271+ (x , p ) => x .orders .some (
278272 (order ) => order .orderID === p .orderID )
279273 )
280274
@@ -324,8 +318,7 @@ passed will be sent as a sql parameter and not as a literal.
324318``` typescript
325319 const prefix = ` ${name }% ` ;
326320 db .customers .where ({ prefix },
327- (p ) =>
328- (customer ) => Sql .text .like (customer .firstName , p .prefix )
321+ (customer , p ) => Sql .text .like (customer .firstName , p .prefix )
329322 || Sql .text .like (customer .lastName p .prefix )
330323 )
331324```
@@ -334,8 +327,7 @@ passed will be sent as a sql parameter and not as a literal.
334327For other sql text functions you can use ` Sql.text.startsWith ` , ` Sql.text.endsWith ` , ` Sql.text.left ` ... etc as shown below.
335328``` typescript
336329 db .customers .where ({ prefix },
337- (p ) =>
338- (customer ) => Sql .text .startsWith (customer .firstName , p .prefix )
330+ (customer , p ) => Sql .text .startsWith (customer .firstName , p .prefix )
339331 || Sql .text .startsWith (customer .lastName p .prefix )
340332 )
341333```
@@ -346,8 +338,7 @@ Just as text functions you can also use date functions as shown below.
346338 const year = (new Date ()).getFullYear ();
347339 // get count of all orders of this year...
348340 db .orders .where ({ year },
349- (p ) =>
350- (order ) => Sql .date .yearOf (order .orderDate ) === p .year
341+ (order , p ) => Sql .date .yearOf (order .orderDate ) === p .year
351342 )
352343
353344 // above example is only for illustrations only, it will not use index.
@@ -356,8 +347,7 @@ Just as text functions you can also use date functions as shown below.
356347 const end: Date = /* start date */ ;
357348 // get count of all orders of this year...
358349 db .orders .where ({ start , end },
359- (p ) =>
360- (order ) => p .start <= order .orderDate && order .orderDate >= p .end
350+ (order , p ) => p .start <= order .orderDate && order .orderDate >= p .end
361351 )
362352
363353```
@@ -422,25 +412,26 @@ within one year.
422412``` typescript
423413 const past365 = DateTime .now .addYears (- 1 );
424414 db .users .asQuery ()
425- .delete ({ past365 }, (p ) =>
426- ( x ) => x .lastLogin < p .past365 )
415+ .delete ({ past365 }, (x , p ) =>
416+ x .lastLogin < p .past365 )
427417```
428418### Insert
429419Following query will insert all old messages to
430420archivedMessages table and delete from messages
431421in a single transaction.
432422
433423Everything happens on database server, no entity
434- is loadded in the memory.
424+ is loaded in the memory.
435425
436426``` typescript
437427 const past365 = DateTime .now .addYears (- 1 );
438428
439429 using tx = await db .connection .createTransaction ();
440430
441431 const oldMessagesQuery = db .messages
442- .where ({ past365 }, (p ) =>
443- (x ) => x .dateCreated < p .past365 );
432+ .where ({ past365 },
433+ (x , p ) =>
434+ x .dateCreated < p .past365 );
444435
445436 oldMessagesQuery .insertInto (db .archivedMessages );
446437
@@ -575,16 +566,16 @@ export class ProductEvents extends EntityEvents<Product> {
575566 // user has purchased or products are
576567 // active.
577568
578- return query .where ({ userID }, (p ) =>
579- p .isActive
569+ return query .where ({ userID }, (x , p ) =>
570+ x .isActive
580571 || x .orderItems .some ((oi ) =>
581572 oi .order .customerID === p .userID
582573 )
583574 );
584575 }
585576
586577 // anonymous users can see only active products
587- return query .where ({ userID }, (p ) => p .isActive === true );
578+ return query .where ({ userID }, (x ) => x .isActive === true );
588579 }
589580
590581 /*
@@ -623,8 +614,8 @@ export class ProductEvents extends EntityEvents<Product> {
623614 // user has purchased or products are
624615 // active.
625616
626- return query .where ({ userID }, (p ) =>
627- p .isActive === true
617+ return query .where ({ userID }, (x , p ) =>
618+ x .isActive === true
628619 || x .orderItems .some ((oi ) =>
629620 oi .order .customerID === p .userID
630621 )
@@ -639,7 +630,7 @@ export class ProductEvents extends EntityEvents<Product> {
639630
640631 }
641632
642- // each of these methods, beforeInsert, afteInsert , beforeUpdate
633+ // each of these methods, beforeInsert, afterInsert , beforeUpdate
643634 // afterUpdate, beforeDelete and afterDelete are asynchronous and
644635 // you can await on async methods.
645636 async afterInsert(entity : Product , entry : ChangeEntry <Product >) {
0 commit comments