velocious 1.0.8 → 1.0.9

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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.8",
6
+ "version": "1.0.9",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "jasmine",
@@ -69,6 +69,15 @@ export default class VelociousDatabaseDriversBase {
69
69
  this.idSeq = id
70
70
  }
71
71
 
72
+ async tableExists(tableName) {
73
+ const tables = await this.getTables()
74
+ const table = tables.find((table) => table.getName() == tableName)
75
+
76
+ if (table) return true
77
+
78
+ return false
79
+ }
80
+
72
81
  async update(...args) {
73
82
  const sql = this.updateSql(...args)
74
83
 
@@ -5,12 +5,11 @@ import Migrator from "./migrator"
5
5
  export default class VelociousDatabaseMigrateFromRequireContext {
6
6
  constructor(configuration) {
7
7
  this.configuration = configuration || Configuration.current()
8
+ this.migrator = new Migrator({configuration: this.configuration})
8
9
  }
9
10
 
10
11
  async execute(requireContext) {
11
- const migrator = new Migrator({configuration: this.configuration})
12
-
13
- await migrator.prepare()
12
+ await this.migrator.prepare()
14
13
 
15
14
  const files = requireContext.keys()
16
15
  .map((file) => {
@@ -32,7 +31,7 @@ export default class VelociousDatabaseMigrateFromRequireContext {
32
31
  .sort((migration1, migration2) => migration1.date - migration2.date)
33
32
 
34
33
  for (const migration of files) {
35
- if (!migrator.hasRunMigrationVersion(migration.date)) {
34
+ if (!this.migrator.hasRunMigrationVersion(migration.date)) {
36
35
  await this.runMigrationFile(migration, requireContext)
37
36
  }
38
37
  }
@@ -77,6 +77,12 @@ export default class VelociousDatabaseRecord {
77
77
  return relationship
78
78
  }
79
79
 
80
+ static getRelationships() {
81
+ if (this._relationships) return Object.values(this._relationships)
82
+
83
+ return []
84
+ }
85
+
80
86
  getRelationshipByName(relationshipName) {
81
87
  if (!this._instanceRelationships) this._instanceRelationships = {}
82
88
 
@@ -308,7 +314,7 @@ export default class VelociousDatabaseRecord {
308
314
 
309
315
  const model = instanceRelationship.loaded()
310
316
 
311
- if (model.isChanged()) {
317
+ if (model?.isChanged()) {
312
318
  await model.save()
313
319
 
314
320
  const foreignKey = instanceRelationship.getForeignKey()
@@ -569,6 +575,13 @@ export default class VelociousDatabaseRecord {
569
575
 
570
576
  await this._reloadWithId(id)
571
577
  this.setIsNewRecord(false)
578
+
579
+ // Mark all relationships as preloaded, since we don't expect anything to have magically appeared since we created the record.
580
+ for (const relationship of this.constructor.getRelationships()) {
581
+ const instanceRelationship = this.getRelationshipByName(relationship.getRelationshipName())
582
+
583
+ instanceRelationship.setPreloaded(true)
584
+ }
572
585
  }
573
586
 
574
587
  async _updateRecordWithChanges() {
@@ -39,9 +39,5 @@ export default class VelociousDatabaseRecordHasManyInstanceRelationship extends
39
39
  this._loaded = models
40
40
  }
41
41
 
42
- setPreloaded(preloadedValue) {
43
- this._preloaded = preloadedValue
44
- }
45
-
46
42
  getTargetModelClass = () => this.relationship.getTargetModelClass()
47
43
  }