@@ -302,33 +302,37 @@ const db = schema(
302
302
{ server : { preferRest : true } } ,
303
303
) ;
304
304
305
- async function custom ( ) {
305
+ //#region schema
306
+ async function schema_ ( ) {
306
307
// Creating custom collection
308
+ {
309
+ // Via constant named property
307
310
308
- // Via constant named property
311
+ const doc = await db [ customCollection ] . get ( await db [ customCollection ] . id ( ) ) ;
312
+ db [ customCollection ] . get ;
313
+ db . customCollectionName . get ;
314
+ doc ?. data . hello ;
309
315
310
- const doc = await db [ customCollection ] . get ( await db [ customCollection ] . id ( ) ) ;
311
- db [ customCollection ] . get ;
312
- db . customCollectionName . get ;
313
- doc ?. data . hello ;
316
+ // Via name variable
314
317
315
- // Via name variable
318
+ async function createDb ( collection : string ) {
319
+ const customDB = schema ( ( $ ) => ( {
320
+ users : $ . collection < User > ( ) ,
321
+ customCollection : $ . collection < CustomCollection > ( ) . name ( collection ) ,
322
+ } ) ) ;
316
323
317
- async function createDb ( collection : string ) {
318
- const customDB = schema ( ( $ ) => ( {
319
- users : $ . collection < User > ( ) ,
320
- customCollection : $ . collection < CustomCollection > ( ) . name ( collection ) ,
321
- } ) ) ;
322
-
323
- const doc = await customDB . customCollection . get (
324
- await customDB . customCollection . id ( ) ,
325
- ) ;
324
+ const doc = await customDB . customCollection . get (
325
+ await customDB . customCollection . id ( ) ,
326
+ ) ;
326
327
327
- doc ?. data . hello ;
328
+ doc ?. data . hello ;
329
+ }
328
330
}
329
331
}
332
+ //#endregion
330
333
331
- async function colleciton ( ) {
334
+ //#region collection
335
+ async function collection ( ) {
332
336
/// Reading generic collections
333
337
334
338
//// Model as generic
@@ -365,8 +369,25 @@ async function colleciton() {
365
369
] ) ;
366
370
things . map ( ( nested ) => nested . map ( ( thing ) => thing . data . name ) ) ;
367
371
}
372
+
373
+ // Count
374
+
375
+ const docsCount = await db . users . count ( ) ;
376
+ docsCount . toFixed ( ) ;
377
+
378
+ const nestedDB = schema ( ( $ ) => ( {
379
+ users : $ . collection < User > ( ) . sub ( {
380
+ settings : $ . collection < { } > ( ) ,
381
+ } ) ,
382
+ } ) ) ;
383
+ const nestedDocsCount = await nestedDB
384
+ . users ( nestedDB . users . id ( "whatever" ) )
385
+ . settings . count ( ) ;
386
+ nestedDocsCount . toFixed ( ) ;
368
387
}
388
+ //#endregion
369
389
390
+ //#region Ref
370
391
async function ref ( ) {
371
392
/// Reading generic refs
372
393
@@ -499,7 +520,9 @@ async function ref() {
499
520
) ;
500
521
}
501
522
}
523
+ //#endregion
502
524
525
+ //#region Doc
503
526
async function doc ( ) {
504
527
const user = db . users . doc ( db . users . id ( "sasha" ) , {
505
528
name : "Sasha" ,
@@ -625,24 +648,9 @@ async function doc() {
625
648
TypeEqual < typeof serverUser . data . alias , string | undefined | null >
626
649
> ( true ) ;
627
650
}
651
+ //#endregion
628
652
629
- async function collection ( ) {
630
- // Count
631
-
632
- const docsCount = await db . users . count ( ) ;
633
- docsCount . toFixed ( ) ;
634
-
635
- const nestedDB = schema ( ( $ ) => ( {
636
- users : $ . collection < User > ( ) . sub ( {
637
- settings : $ . collection < { } > ( ) ,
638
- } ) ,
639
- } ) ) ;
640
- const nestedDocsCount = await nestedDB
641
- . users ( nestedDB . users . id ( "whatever" ) )
642
- . settings . count ( ) ;
643
- nestedDocsCount . toFixed ( ) ;
644
- }
645
-
653
+ //#region get
646
654
async function get ( ) {
647
655
const user = await db . users . get ( db . users . id ( "sasha" ) ) ;
648
656
if ( ! user ) return ;
@@ -741,7 +749,9 @@ async function get() {
741
749
true ,
742
750
) ;
743
751
}
752
+ //#endregion
744
753
754
+ //#region many
745
755
async function many ( ) {
746
756
const [ user ] = await db . users . many ( [ db . users . id ( "sasha" ) ] ) ;
747
757
if ( ! user ) return ;
@@ -830,7 +840,9 @@ async function many() {
830
840
true ,
831
841
) ;
832
842
}
843
+ //#endregion
833
844
845
+ //#region all
834
846
async function all ( ) {
835
847
const [ user ] = await db . users . all ( ) ;
836
848
if ( ! user ) return ;
@@ -923,7 +935,9 @@ async function all() {
923
935
true ,
924
936
) ;
925
937
}
938
+ //#endregion
926
939
940
+ //#region query
927
941
async function query ( ) {
928
942
const [ user ] = await db . users . query ( ( $ ) => $ . field ( "name" ) . eq ( "Sasha" ) ) ;
929
943
if ( ! user ) return ;
@@ -1326,7 +1340,9 @@ async function query() {
1326
1340
) ,
1327
1341
) ;
1328
1342
}
1343
+ //#endregion
1329
1344
1345
+ //#region
1330
1346
async function add ( ) {
1331
1347
// Simple add
1332
1348
@@ -1390,7 +1406,9 @@ async function add() {
1390
1406
status : null ,
1391
1407
} ) ) ;
1392
1408
}
1409
+ //#endregion
1393
1410
1411
+ //#region set
1394
1412
async function set ( ) {
1395
1413
// Simple set
1396
1414
@@ -1507,7 +1525,9 @@ async function set() {
1507
1525
status : null ,
1508
1526
} ) ) ;
1509
1527
}
1528
+ //#endregion
1510
1529
1530
+ //#region upset
1511
1531
async function upset ( ) {
1512
1532
// Simple set
1513
1533
@@ -1688,7 +1708,9 @@ async function upset() {
1688
1708
status : null ,
1689
1709
} ) ) ;
1690
1710
}
1711
+ //#endregion
1691
1712
1713
+ //#region update
1692
1714
async function update ( ) {
1693
1715
// Simple update
1694
1716
@@ -2503,6 +2525,7 @@ async function update() {
2503
2525
active : true ;
2504
2526
}
2505
2527
}
2528
+ //#endregion
2506
2529
2507
2530
async function sharedIds ( ) {
2508
2531
interface Settings {
@@ -2521,6 +2544,7 @@ async function sharedIds() {
2521
2544
2522
2545
// @tysts -start: strict - with strictNullChecks disabled the tysts fail
2523
2546
2547
+ //#region InferSchema
2524
2548
async function inferSchema ( ) {
2525
2549
type Schema1 = Core . InferSchema < typeof db > ;
2526
2550
@@ -2565,7 +2589,9 @@ async function inferSchema() {
2565
2589
>
2566
2590
> ( true ) ;
2567
2591
}
2592
+ //#endregion
2568
2593
2594
+ //#region NarrowDoc
2569
2595
async function narrowDoc ( ) {
2570
2596
interface TwitterAccount {
2571
2597
type : "twitter" ;
@@ -2601,6 +2627,7 @@ async function narrowDoc() {
2601
2627
>
2602
2628
> ( true ) ;
2603
2629
}
2630
+ //#endregion
2604
2631
2605
2632
async function edgeCases ( ) {
2606
2633
interface ServerChapter { }
0 commit comments