query-core 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,9 @@ var SearchBuilder = (function () {
20
20
  this.map = meta.map;
21
21
  this.bools = meta.bools;
22
22
  this.primaryKeys = meta.keys;
23
+ this.version = meta.version;
24
+ this.createdAt = meta.createdAt;
25
+ this.updatedAt = meta.updatedAt;
23
26
  }
24
27
  else {
25
28
  this.primaryKeys = [];
package/lib/services.js CHANGED
@@ -552,9 +552,9 @@ var SqlSearchWriter = (function (_super) {
552
552
  _this.db = db;
553
553
  _this.attributes = attributes;
554
554
  _this.toDB = toDB;
555
- var x = build_1.version(attributes);
555
+ var x = build_1.buildMetadata(attributes);
556
556
  if (x) {
557
- _this.version = x.name;
557
+ _this.version = x.version;
558
558
  }
559
559
  _this.create = _this.create.bind(_this);
560
560
  _this.update = _this.update.bind(_this);
@@ -566,6 +566,12 @@ var SqlSearchWriter = (function (_super) {
566
566
  if (this.toDB) {
567
567
  obj2 = this.toDB(obj);
568
568
  }
569
+ if (this.createdAt) {
570
+ obj2[this.createdAt] = new Date();
571
+ }
572
+ if (this.updatedAt) {
573
+ obj2[this.updatedAt] = new Date();
574
+ }
569
575
  var stmt = build_1.buildToInsert(obj2, this.table, this.attributes, this.db.param, this.version);
570
576
  if (stmt.query) {
571
577
  var db = tx ? tx : this.db;
@@ -587,6 +593,9 @@ var SqlSearchWriter = (function (_super) {
587
593
  if (this.toDB) {
588
594
  obj2 = this.toDB(obj);
589
595
  }
596
+ if (this.updatedAt) {
597
+ obj2[this.updatedAt] = new Date();
598
+ }
590
599
  var stmt = build_1.buildToUpdate(obj2, this.table, this.attributes, this.db.param, this.version);
591
600
  if (stmt.query) {
592
601
  var db = tx ? tx : this.db;
@@ -604,7 +613,7 @@ var SqlSearchWriter = (function (_super) {
604
613
  exports.SqlSearchWriter = SqlSearchWriter;
605
614
  var SqlRepository = (function (_super) {
606
615
  __extends(SqlRepository, _super);
607
- function SqlRepository(db, table, attributes, buildQ, toDB, fromDB, sort, q, excluding, buildSort, buildParam, total) {
616
+ function SqlRepository(db, table, attributes, buildQ, toDB, fromDB, sort, q, excluding, buildSort, total) {
608
617
  var _this = _super.call(this, db, table, attributes, buildQ, toDB, fromDB, sort, q, excluding, buildSort, total) || this;
609
618
  _this.attributes = attributes;
610
619
  _this.toDB = toDB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-core",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "query",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
@@ -17,6 +17,9 @@ export class SearchBuilder<T, S> {
17
17
  protected map?: StringMap
18
18
  protected bools?: Attribute[]
19
19
  protected primaryKeys: Attribute[]
20
+ protected version?: string
21
+ protected createdAt?: string
22
+ protected updatedAt?: string
20
23
  protected buildQuery: (
21
24
  s: S,
22
25
  param: (i: number) => string,
@@ -62,6 +65,9 @@ export class SearchBuilder<T, S> {
62
65
  this.map = meta.map
63
66
  this.bools = meta.bools
64
67
  this.primaryKeys = meta.keys
68
+ this.version = meta.version
69
+ this.createdAt = meta.createdAt
70
+ this.updatedAt = meta.updatedAt
65
71
  } else {
66
72
  this.primaryKeys = []
67
73
  }
package/src/services.ts CHANGED
@@ -597,7 +597,6 @@ export const GenericRepository = CRUDRepository
597
597
  export const SqlGenericRepository = CRUDRepository
598
598
 
599
599
  export class SqlSearchWriter<T, S> extends SearchBuilder<T, S> {
600
- protected version?: string
601
600
  constructor(
602
601
  protected db: Executor,
603
602
  table: string,
@@ -623,19 +622,25 @@ export class SqlSearchWriter<T, S> extends SearchBuilder<T, S> {
623
622
  total?: string,
624
623
  ) {
625
624
  super(db, table, attributes, buildQ, fromDB, sort, q, excluding, buildSort, total)
626
- const x = version(attributes)
625
+ const x = buildMetadata(attributes)
627
626
  if (x) {
628
- this.version = x.name
627
+ this.version = x.version
629
628
  }
630
629
  this.create = this.create.bind(this)
631
630
  this.update = this.update.bind(this)
632
631
  this.patch = this.patch.bind(this)
633
632
  }
634
633
  create(obj: T, tx?: Transaction): Promise<number> {
635
- let obj2 = obj
634
+ let obj2: any = obj
636
635
  if (this.toDB) {
637
636
  obj2 = this.toDB(obj)
638
637
  }
638
+ if (this.createdAt) {
639
+ obj2[this.createdAt] = new Date()
640
+ }
641
+ if (this.updatedAt) {
642
+ obj2[this.updatedAt] = new Date()
643
+ }
639
644
  const stmt = buildToInsert(obj2, this.table, this.attributes, this.db.param, this.version)
640
645
  if (stmt.query) {
641
646
  const db = tx ? tx: this.db
@@ -651,10 +656,13 @@ export class SqlSearchWriter<T, S> extends SearchBuilder<T, S> {
651
656
  }
652
657
  }
653
658
  update(obj: T, tx?: Transaction): Promise<number> {
654
- let obj2 = obj
659
+ let obj2: any = obj
655
660
  if (this.toDB) {
656
661
  obj2 = this.toDB(obj)
657
662
  }
663
+ if (this.updatedAt) {
664
+ obj2[this.updatedAt] = new Date()
665
+ }
658
666
  const stmt = buildToUpdate(obj2, this.table, this.attributes, this.db.param, this.version)
659
667
  if (stmt.query) {
660
668
  const db = tx ? tx: this.db
@@ -691,7 +699,6 @@ export class SqlRepository<T, ID, S> extends SqlSearchWriter<T, S> {
691
699
  q?: string,
692
700
  excluding?: string,
693
701
  buildSort?: (sort?: string, map?: Attributes | StringMap) => string,
694
- buildParam?: (i: number) => string,
695
702
  total?: string,
696
703
  ) {
697
704
  super(db, table, attributes, buildQ, toDB, fromDB, sort, q, excluding, buildSort, total)