@anfenn/dync 1.0.19 → 1.0.20
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/{chunk-WZ7V4U6Z.js → chunk-I2KQD4DD.js} +35 -23
- package/dist/chunk-I2KQD4DD.js.map +1 -0
- package/dist/index.cjs +34 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/src/storage/sqlite/SQLiteCollection.ts +19 -13
- package/src/storage/sqlite/helpers.ts +21 -9
- package/src/storage/sqlite/types.ts +5 -2
- package/dist/chunk-WZ7V4U6Z.js.map +0 -1
|
@@ -2307,7 +2307,7 @@ var MemoryAdapter = class {
|
|
|
2307
2307
|
var SQLITE_SCHEMA_VERSION_STATE_KEY = "sqlite_schema_version";
|
|
2308
2308
|
var DEFAULT_STREAM_BATCH_SIZE = 200;
|
|
2309
2309
|
var createDefaultState2 = () => ({
|
|
2310
|
-
|
|
2310
|
+
orGroups: [[]],
|
|
2311
2311
|
jsPredicate: void 0,
|
|
2312
2312
|
orderBy: void 0,
|
|
2313
2313
|
reverse: false,
|
|
@@ -2315,19 +2315,26 @@ var createDefaultState2 = () => ({
|
|
|
2315
2315
|
limit: void 0,
|
|
2316
2316
|
distinct: false
|
|
2317
2317
|
});
|
|
2318
|
-
var buildWhereClause = (
|
|
2319
|
-
|
|
2318
|
+
var buildWhereClause = (orGroups) => {
|
|
2319
|
+
const nonEmptyGroups = orGroups.filter((group) => group.length > 0);
|
|
2320
|
+
if (nonEmptyGroups.length === 0) {
|
|
2320
2321
|
return { whereClause: "", parameters: [] };
|
|
2321
2322
|
}
|
|
2322
|
-
const
|
|
2323
|
+
const groupClauses = [];
|
|
2323
2324
|
const parameters = [];
|
|
2324
|
-
for (const
|
|
2325
|
-
const
|
|
2326
|
-
|
|
2327
|
-
|
|
2325
|
+
for (const group of nonEmptyGroups) {
|
|
2326
|
+
const conditionClauses = [];
|
|
2327
|
+
for (const condition of group) {
|
|
2328
|
+
const built = buildCondition(condition);
|
|
2329
|
+
conditionClauses.push(built.clause);
|
|
2330
|
+
parameters.push(...built.parameters);
|
|
2331
|
+
}
|
|
2332
|
+
const groupClause = conditionClauses.length === 1 ? conditionClauses[0] : `(${conditionClauses.join(" AND ")})`;
|
|
2333
|
+
groupClauses.push(groupClause);
|
|
2328
2334
|
}
|
|
2335
|
+
const whereContent = groupClauses.length === 1 ? groupClauses[0] : `(${groupClauses.join(" OR ")})`;
|
|
2329
2336
|
return {
|
|
2330
|
-
whereClause: `WHERE ${
|
|
2337
|
+
whereClause: `WHERE ${whereContent}`,
|
|
2331
2338
|
parameters
|
|
2332
2339
|
};
|
|
2333
2340
|
};
|
|
@@ -3578,25 +3585,26 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3578
3585
|
this.state = {
|
|
3579
3586
|
...base,
|
|
3580
3587
|
...state,
|
|
3581
|
-
|
|
3588
|
+
orGroups: state?.orGroups ?? base.orGroups,
|
|
3582
3589
|
jsPredicate: state?.jsPredicate
|
|
3583
3590
|
};
|
|
3584
3591
|
}
|
|
3585
3592
|
getState() {
|
|
3586
|
-
return { ...this.state,
|
|
3593
|
+
return { ...this.state, orGroups: this.state.orGroups.map((g) => [...g]) };
|
|
3587
3594
|
}
|
|
3588
|
-
// Add a SQL-expressible condition to
|
|
3595
|
+
// Add a SQL-expressible condition to the current OR group
|
|
3589
3596
|
addSqlCondition(condition) {
|
|
3597
|
+
const newGroups = this.state.orGroups.map((g, i) => i === this.state.orGroups.length - 1 ? [...g, condition] : g);
|
|
3590
3598
|
return new _SQLiteCollection(this.table, {
|
|
3591
3599
|
...this.state,
|
|
3592
|
-
|
|
3600
|
+
orGroups: newGroups
|
|
3593
3601
|
});
|
|
3594
3602
|
}
|
|
3595
3603
|
replicate(overrides) {
|
|
3596
3604
|
return new _SQLiteCollection(this.table, {
|
|
3597
3605
|
...this.state,
|
|
3598
3606
|
...overrides,
|
|
3599
|
-
|
|
3607
|
+
orGroups: overrides?.orGroups ?? this.state.orGroups,
|
|
3600
3608
|
jsPredicate: overrides?.jsPredicate !== void 0 ? overrides.jsPredicate : this.state.jsPredicate
|
|
3601
3609
|
});
|
|
3602
3610
|
}
|
|
@@ -3622,7 +3630,7 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3622
3630
|
* and apply them after JS filtering.
|
|
3623
3631
|
*/
|
|
3624
3632
|
async executeQuery(options = {}) {
|
|
3625
|
-
const { whereClause, parameters } = buildWhereClause(this.state.
|
|
3633
|
+
const { whereClause, parameters } = buildWhereClause(this.state.orGroups);
|
|
3626
3634
|
const ordering = options.orderByOverride ?? this.resolveOrdering();
|
|
3627
3635
|
const cloneValues = options.clone !== false;
|
|
3628
3636
|
const hasJsFilter = this.hasJsPredicate();
|
|
@@ -3689,7 +3697,7 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3689
3697
|
}
|
|
3690
3698
|
async keys() {
|
|
3691
3699
|
if (!this.hasJsPredicate()) {
|
|
3692
|
-
const { whereClause, parameters } = buildWhereClause(this.state.
|
|
3700
|
+
const { whereClause, parameters } = buildWhereClause(this.state.orGroups);
|
|
3693
3701
|
const ordering = this.resolveOrdering();
|
|
3694
3702
|
return this.table.queryKeysWithConditions({
|
|
3695
3703
|
whereClause,
|
|
@@ -3708,7 +3716,7 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3708
3716
|
}
|
|
3709
3717
|
async uniqueKeys() {
|
|
3710
3718
|
if (!this.hasJsPredicate()) {
|
|
3711
|
-
const { whereClause, parameters } = buildWhereClause(this.state.
|
|
3719
|
+
const { whereClause, parameters } = buildWhereClause(this.state.orGroups);
|
|
3712
3720
|
const ordering = this.resolveOrdering();
|
|
3713
3721
|
return this.table.queryKeysWithConditions({
|
|
3714
3722
|
whereClause,
|
|
@@ -3725,8 +3733,8 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3725
3733
|
async count() {
|
|
3726
3734
|
if (!this.hasJsPredicate()) {
|
|
3727
3735
|
return this.table.countWithConditions({
|
|
3728
|
-
whereClause: buildWhereClause(this.state.
|
|
3729
|
-
parameters: buildWhereClause(this.state.
|
|
3736
|
+
whereClause: buildWhereClause(this.state.orGroups).whereClause,
|
|
3737
|
+
parameters: buildWhereClause(this.state.orGroups).parameters,
|
|
3730
3738
|
distinct: this.state.distinct
|
|
3731
3739
|
});
|
|
3732
3740
|
}
|
|
@@ -3746,7 +3754,11 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3746
3754
|
return this.withJsPredicate((record) => predicate(cloneValue(record)));
|
|
3747
3755
|
}
|
|
3748
3756
|
or(index) {
|
|
3749
|
-
|
|
3757
|
+
const newCollection = new _SQLiteCollection(this.table, {
|
|
3758
|
+
...this.state,
|
|
3759
|
+
orGroups: [...this.state.orGroups, []]
|
|
3760
|
+
});
|
|
3761
|
+
return this.table.createWhereClause(index, newCollection);
|
|
3750
3762
|
}
|
|
3751
3763
|
clone(_props) {
|
|
3752
3764
|
return this.replicate();
|
|
@@ -3765,7 +3777,7 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3765
3777
|
}
|
|
3766
3778
|
async delete() {
|
|
3767
3779
|
if (!this.hasJsPredicate()) {
|
|
3768
|
-
const { whereClause, parameters } = buildWhereClause(this.state.
|
|
3780
|
+
const { whereClause, parameters } = buildWhereClause(this.state.orGroups);
|
|
3769
3781
|
return this.table.deleteWithConditions({ whereClause, parameters });
|
|
3770
3782
|
}
|
|
3771
3783
|
const entries = await this.executeQuery({ clone: false });
|
|
@@ -3776,7 +3788,7 @@ var SQLiteCollection2 = class _SQLiteCollection {
|
|
|
3776
3788
|
}
|
|
3777
3789
|
async modify(changes) {
|
|
3778
3790
|
if (typeof changes !== "function" && !this.hasJsPredicate()) {
|
|
3779
|
-
const { whereClause, parameters } = buildWhereClause(this.state.
|
|
3791
|
+
const { whereClause, parameters } = buildWhereClause(this.state.orGroups);
|
|
3780
3792
|
return this.table.updateWithConditions({ whereClause, parameters, changes });
|
|
3781
3793
|
}
|
|
3782
3794
|
const entries = await this.executeQuery();
|
|
@@ -3806,4 +3818,4 @@ export {
|
|
|
3806
3818
|
SqliteQueryContext,
|
|
3807
3819
|
SQLiteAdapter2 as SQLiteAdapter
|
|
3808
3820
|
};
|
|
3809
|
-
//# sourceMappingURL=chunk-
|
|
3821
|
+
//# sourceMappingURL=chunk-I2KQD4DD.js.map
|