bun-query-builder 0.1.38 → 0.1.40
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/dist/bin/cli.js +39 -15
- package/dist/src/index.js +38 -14
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -18684,11 +18684,15 @@ async function resetDatabase(dir, opts = {}) {
|
|
|
18684
18684
|
} else {
|
|
18685
18685
|
info("-- No enum types found to drop");
|
|
18686
18686
|
}
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18687
|
+
if (tableNames.length > 0) {
|
|
18688
|
+
try {
|
|
18689
|
+
await deleteMigrationFiles(dir, workspaceRoot, opts);
|
|
18690
|
+
} catch (err) {
|
|
18691
|
+
console.error(err);
|
|
18692
|
+
info("-- Could not clean up migration files");
|
|
18693
|
+
}
|
|
18694
|
+
} else {
|
|
18695
|
+
info("-- No models directory found; keeping committed migration files in place");
|
|
18692
18696
|
}
|
|
18693
18697
|
try {
|
|
18694
18698
|
await clearGeneratedDirectory(workspaceRoot);
|
|
@@ -24513,6 +24517,25 @@ function collectBelongsToManyKeys(definition) {
|
|
|
24513
24517
|
btmKeysCache.set(definition, keys);
|
|
24514
24518
|
return keys;
|
|
24515
24519
|
}
|
|
24520
|
+
function normalizeAttributeKeys(data) {
|
|
24521
|
+
const result = {};
|
|
24522
|
+
for (const [key, value] of Object.entries(data)) {
|
|
24523
|
+
result[toSnakeCase(key)] = value;
|
|
24524
|
+
}
|
|
24525
|
+
return result;
|
|
24526
|
+
}
|
|
24527
|
+
function findAttributeDef(attrs, key) {
|
|
24528
|
+
if (attrs[key])
|
|
24529
|
+
return attrs[key];
|
|
24530
|
+
const snake = toSnakeCase(key);
|
|
24531
|
+
if (attrs[snake])
|
|
24532
|
+
return attrs[snake];
|
|
24533
|
+
for (const k2 of Object.keys(attrs)) {
|
|
24534
|
+
if (toSnakeCase(k2) === snake)
|
|
24535
|
+
return attrs[k2];
|
|
24536
|
+
}
|
|
24537
|
+
return;
|
|
24538
|
+
}
|
|
24516
24539
|
|
|
24517
24540
|
class ModelInstance {
|
|
24518
24541
|
_attributes;
|
|
@@ -24522,7 +24545,7 @@ class ModelInstance {
|
|
|
24522
24545
|
_relations = {};
|
|
24523
24546
|
constructor(definition, attributes = {}) {
|
|
24524
24547
|
this._definition = definition;
|
|
24525
|
-
this._attributes = { ...attributes };
|
|
24548
|
+
this._attributes = normalizeAttributeKeys({ ...attributes });
|
|
24526
24549
|
this._original = null;
|
|
24527
24550
|
const btmKeys = collectBelongsToManyKeys(definition);
|
|
24528
24551
|
if (btmKeys.size === 0)
|
|
@@ -24562,10 +24585,10 @@ class ModelInstance {
|
|
|
24562
24585
|
return v2;
|
|
24563
24586
|
} catch {}
|
|
24564
24587
|
}
|
|
24565
|
-
return this._attributes[key];
|
|
24588
|
+
return this._attributes[toSnakeCase(key)];
|
|
24566
24589
|
}
|
|
24567
24590
|
getAttribute(key) {
|
|
24568
|
-
return this._attributes[key];
|
|
24591
|
+
return this._attributes[toSnakeCase(key)];
|
|
24569
24592
|
}
|
|
24570
24593
|
getAttributes() {
|
|
24571
24594
|
return { ...this._attributes };
|
|
@@ -24573,7 +24596,7 @@ class ModelInstance {
|
|
|
24573
24596
|
set(key, value) {
|
|
24574
24597
|
if (this._original === null)
|
|
24575
24598
|
this._original = { ...this._attributes };
|
|
24576
|
-
this._attributes[key] = value;
|
|
24599
|
+
this._attributes[toSnakeCase(key)] = value;
|
|
24577
24600
|
}
|
|
24578
24601
|
only(keys) {
|
|
24579
24602
|
const out = {};
|
|
@@ -24636,11 +24659,11 @@ class ModelInstance {
|
|
|
24636
24659
|
fill(data) {
|
|
24637
24660
|
const attrs = this._definition.attributes;
|
|
24638
24661
|
for (const [key, value] of Object.entries(data)) {
|
|
24639
|
-
const attr = attrs
|
|
24662
|
+
const attr = findAttributeDef(attrs, key);
|
|
24640
24663
|
if (attr?.fillable && !attr?.guarded) {
|
|
24641
24664
|
if (this._original === null)
|
|
24642
24665
|
this._original = { ...this._attributes };
|
|
24643
|
-
this._attributes[key] = value;
|
|
24666
|
+
this._attributes[toSnakeCase(key)] = value;
|
|
24644
24667
|
}
|
|
24645
24668
|
}
|
|
24646
24669
|
return this;
|
|
@@ -24648,7 +24671,7 @@ class ModelInstance {
|
|
|
24648
24671
|
forceFill(data) {
|
|
24649
24672
|
if (this._original === null)
|
|
24650
24673
|
this._original = { ...this._attributes };
|
|
24651
|
-
Object.assign(this._attributes, data);
|
|
24674
|
+
Object.assign(this._attributes, normalizeAttributeKeys(data));
|
|
24652
24675
|
return this;
|
|
24653
24676
|
}
|
|
24654
24677
|
async save() {
|
|
@@ -24682,8 +24705,9 @@ class ModelInstance {
|
|
|
24682
24705
|
for (const [key, attr] of Object.entries(attrs)) {
|
|
24683
24706
|
if (attr.guarded)
|
|
24684
24707
|
continue;
|
|
24685
|
-
|
|
24686
|
-
|
|
24708
|
+
const col = toSnakeCase(key);
|
|
24709
|
+
if (this._attributes[col] !== undefined) {
|
|
24710
|
+
data[col] = this._attributes[col];
|
|
24687
24711
|
}
|
|
24688
24712
|
}
|
|
24689
24713
|
if (timestampsEnabled(this._definition)) {
|
|
@@ -30744,7 +30768,7 @@ function getPrefix() {
|
|
|
30744
30768
|
}
|
|
30745
30769
|
var prefix = getPrefix();
|
|
30746
30770
|
// package.json
|
|
30747
|
-
var version2 = "0.1.
|
|
30771
|
+
var version2 = "0.1.40";
|
|
30748
30772
|
|
|
30749
30773
|
// bin/cli.ts
|
|
30750
30774
|
init_actions();
|
package/dist/src/index.js
CHANGED
|
@@ -18684,11 +18684,15 @@ async function resetDatabase(dir, opts = {}) {
|
|
|
18684
18684
|
} else {
|
|
18685
18685
|
info("-- No enum types found to drop");
|
|
18686
18686
|
}
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18687
|
+
if (tableNames.length > 0) {
|
|
18688
|
+
try {
|
|
18689
|
+
await deleteMigrationFiles(dir, workspaceRoot, opts);
|
|
18690
|
+
} catch (err) {
|
|
18691
|
+
console.error(err);
|
|
18692
|
+
info("-- Could not clean up migration files");
|
|
18693
|
+
}
|
|
18694
|
+
} else {
|
|
18695
|
+
info("-- No models directory found; keeping committed migration files in place");
|
|
18692
18696
|
}
|
|
18693
18697
|
try {
|
|
18694
18698
|
await clearGeneratedDirectory(workspaceRoot);
|
|
@@ -24513,6 +24517,25 @@ function collectBelongsToManyKeys(definition) {
|
|
|
24513
24517
|
btmKeysCache.set(definition, keys);
|
|
24514
24518
|
return keys;
|
|
24515
24519
|
}
|
|
24520
|
+
function normalizeAttributeKeys(data) {
|
|
24521
|
+
const result = {};
|
|
24522
|
+
for (const [key, value] of Object.entries(data)) {
|
|
24523
|
+
result[toSnakeCase(key)] = value;
|
|
24524
|
+
}
|
|
24525
|
+
return result;
|
|
24526
|
+
}
|
|
24527
|
+
function findAttributeDef(attrs, key) {
|
|
24528
|
+
if (attrs[key])
|
|
24529
|
+
return attrs[key];
|
|
24530
|
+
const snake = toSnakeCase(key);
|
|
24531
|
+
if (attrs[snake])
|
|
24532
|
+
return attrs[snake];
|
|
24533
|
+
for (const k2 of Object.keys(attrs)) {
|
|
24534
|
+
if (toSnakeCase(k2) === snake)
|
|
24535
|
+
return attrs[k2];
|
|
24536
|
+
}
|
|
24537
|
+
return;
|
|
24538
|
+
}
|
|
24516
24539
|
|
|
24517
24540
|
class ModelInstance {
|
|
24518
24541
|
_attributes;
|
|
@@ -24522,7 +24545,7 @@ class ModelInstance {
|
|
|
24522
24545
|
_relations = {};
|
|
24523
24546
|
constructor(definition, attributes = {}) {
|
|
24524
24547
|
this._definition = definition;
|
|
24525
|
-
this._attributes = { ...attributes };
|
|
24548
|
+
this._attributes = normalizeAttributeKeys({ ...attributes });
|
|
24526
24549
|
this._original = null;
|
|
24527
24550
|
const btmKeys = collectBelongsToManyKeys(definition);
|
|
24528
24551
|
if (btmKeys.size === 0)
|
|
@@ -24562,10 +24585,10 @@ class ModelInstance {
|
|
|
24562
24585
|
return v2;
|
|
24563
24586
|
} catch {}
|
|
24564
24587
|
}
|
|
24565
|
-
return this._attributes[key];
|
|
24588
|
+
return this._attributes[toSnakeCase(key)];
|
|
24566
24589
|
}
|
|
24567
24590
|
getAttribute(key) {
|
|
24568
|
-
return this._attributes[key];
|
|
24591
|
+
return this._attributes[toSnakeCase(key)];
|
|
24569
24592
|
}
|
|
24570
24593
|
getAttributes() {
|
|
24571
24594
|
return { ...this._attributes };
|
|
@@ -24573,7 +24596,7 @@ class ModelInstance {
|
|
|
24573
24596
|
set(key, value) {
|
|
24574
24597
|
if (this._original === null)
|
|
24575
24598
|
this._original = { ...this._attributes };
|
|
24576
|
-
this._attributes[key] = value;
|
|
24599
|
+
this._attributes[toSnakeCase(key)] = value;
|
|
24577
24600
|
}
|
|
24578
24601
|
only(keys) {
|
|
24579
24602
|
const out = {};
|
|
@@ -24636,11 +24659,11 @@ class ModelInstance {
|
|
|
24636
24659
|
fill(data) {
|
|
24637
24660
|
const attrs = this._definition.attributes;
|
|
24638
24661
|
for (const [key, value] of Object.entries(data)) {
|
|
24639
|
-
const attr = attrs
|
|
24662
|
+
const attr = findAttributeDef(attrs, key);
|
|
24640
24663
|
if (attr?.fillable && !attr?.guarded) {
|
|
24641
24664
|
if (this._original === null)
|
|
24642
24665
|
this._original = { ...this._attributes };
|
|
24643
|
-
this._attributes[key] = value;
|
|
24666
|
+
this._attributes[toSnakeCase(key)] = value;
|
|
24644
24667
|
}
|
|
24645
24668
|
}
|
|
24646
24669
|
return this;
|
|
@@ -24648,7 +24671,7 @@ class ModelInstance {
|
|
|
24648
24671
|
forceFill(data) {
|
|
24649
24672
|
if (this._original === null)
|
|
24650
24673
|
this._original = { ...this._attributes };
|
|
24651
|
-
Object.assign(this._attributes, data);
|
|
24674
|
+
Object.assign(this._attributes, normalizeAttributeKeys(data));
|
|
24652
24675
|
return this;
|
|
24653
24676
|
}
|
|
24654
24677
|
async save() {
|
|
@@ -24682,8 +24705,9 @@ class ModelInstance {
|
|
|
24682
24705
|
for (const [key, attr] of Object.entries(attrs)) {
|
|
24683
24706
|
if (attr.guarded)
|
|
24684
24707
|
continue;
|
|
24685
|
-
|
|
24686
|
-
|
|
24708
|
+
const col = toSnakeCase(key);
|
|
24709
|
+
if (this._attributes[col] !== undefined) {
|
|
24710
|
+
data[col] = this._attributes[col];
|
|
24687
24711
|
}
|
|
24688
24712
|
}
|
|
24689
24713
|
if (timestampsEnabled(this._definition)) {
|
package/package.json
CHANGED