bun-query-builder 0.1.32 → 0.1.33
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 +23 -37
- package/dist/src/index.js +22 -36
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -12835,7 +12835,7 @@ function createQueryBuilder(state) {
|
|
|
12835
12835
|
};
|
|
12836
12836
|
const addWhereText = (prefix, clause) => {
|
|
12837
12837
|
const hasWhere = SQL_PATTERNS.WHERE.test(text);
|
|
12838
|
-
const p = hasWhere ?
|
|
12838
|
+
const p = !hasWhere ? "WHERE" : prefix === "WHERE" ? "AND" : prefix;
|
|
12839
12839
|
text = `${text} ${p} ${clause}`;
|
|
12840
12840
|
};
|
|
12841
12841
|
const appendSetOp = (op, other) => {
|
|
@@ -13993,87 +13993,71 @@ function createQueryBuilder(state) {
|
|
|
13993
13993
|
return this;
|
|
13994
13994
|
},
|
|
13995
13995
|
whereLike(column, pattern, caseSensitive = false) {
|
|
13996
|
-
const expr = caseSensitive ? sql`${sql(String(column))} LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
13997
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
13998
13996
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
13999
13997
|
addWhereText("WHERE", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14000
13998
|
whereParams.push(pattern);
|
|
13999
|
+
built = null;
|
|
14001
14000
|
return this;
|
|
14002
14001
|
},
|
|
14003
14002
|
whereILike(column, pattern) {
|
|
14004
14003
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14005
|
-
if (config5.dialect === "postgres")
|
|
14006
|
-
built = sql`${ensureBuilt()} WHERE ${sql(String(column))} ILIKE ${pattern}`;
|
|
14004
|
+
if (config5.dialect === "postgres")
|
|
14007
14005
|
addWhereText("WHERE", `${String(column)} ILIKE ${ph}`);
|
|
14008
|
-
|
|
14009
|
-
const expr = sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
14010
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
14006
|
+
else
|
|
14011
14007
|
addWhereText("WHERE", `LOWER(${String(column)}) LIKE LOWER(${ph})`);
|
|
14012
|
-
}
|
|
14013
14008
|
whereParams.push(pattern);
|
|
14009
|
+
built = null;
|
|
14014
14010
|
return this;
|
|
14015
14011
|
},
|
|
14016
14012
|
orWhereLike(column, pattern, caseSensitive = false) {
|
|
14017
|
-
const expr = caseSensitive ? sql`${sql(String(column))} LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
14018
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14019
14013
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14020
14014
|
addWhereText("OR", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14021
14015
|
whereParams.push(pattern);
|
|
14016
|
+
built = null;
|
|
14022
14017
|
return this;
|
|
14023
14018
|
},
|
|
14024
14019
|
orWhereILike(column, pattern) {
|
|
14025
14020
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14026
|
-
if (config5.dialect === "postgres")
|
|
14027
|
-
built = sql`${ensureBuilt()} OR ${sql(String(column))} ILIKE ${pattern}`;
|
|
14021
|
+
if (config5.dialect === "postgres")
|
|
14028
14022
|
addWhereText("OR", `${String(column)} ILIKE ${ph}`);
|
|
14029
|
-
|
|
14030
|
-
const expr = sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
14031
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14023
|
+
else
|
|
14032
14024
|
addWhereText("OR", `LOWER(${String(column)}) LIKE LOWER(${ph})`);
|
|
14033
|
-
}
|
|
14034
14025
|
whereParams.push(pattern);
|
|
14026
|
+
built = null;
|
|
14035
14027
|
return this;
|
|
14036
14028
|
},
|
|
14037
14029
|
whereNotLike(column, pattern, caseSensitive = false) {
|
|
14038
|
-
const expr = caseSensitive ? sql`${sql(String(column))} NOT LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14039
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
14040
14030
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14041
14031
|
addWhereText("WHERE", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} NOT LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14042
14032
|
whereParams.push(pattern);
|
|
14033
|
+
built = null;
|
|
14043
14034
|
return this;
|
|
14044
14035
|
},
|
|
14045
14036
|
whereNotILike(column, pattern) {
|
|
14046
14037
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14047
|
-
if (config5.dialect === "postgres")
|
|
14048
|
-
built = sql`${ensureBuilt()} WHERE ${sql(String(column))} NOT ILIKE ${pattern}`;
|
|
14038
|
+
if (config5.dialect === "postgres")
|
|
14049
14039
|
addWhereText("WHERE", `${String(column)} NOT ILIKE ${ph}`);
|
|
14050
|
-
|
|
14051
|
-
const expr = sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14052
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
14040
|
+
else
|
|
14053
14041
|
addWhereText("WHERE", `LOWER(${String(column)}) NOT LIKE LOWER(${ph})`);
|
|
14054
|
-
}
|
|
14055
14042
|
whereParams.push(pattern);
|
|
14043
|
+
built = null;
|
|
14056
14044
|
return this;
|
|
14057
14045
|
},
|
|
14058
14046
|
orWhereNotLike(column, pattern, caseSensitive = false) {
|
|
14059
|
-
const expr = caseSensitive ? sql`${sql(String(column))} NOT LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14060
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14061
14047
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14062
14048
|
addWhereText("OR", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} NOT LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14063
14049
|
whereParams.push(pattern);
|
|
14050
|
+
built = null;
|
|
14064
14051
|
return this;
|
|
14065
14052
|
},
|
|
14066
14053
|
orWhereNotILike(column, pattern) {
|
|
14067
14054
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14068
|
-
if (config5.dialect === "postgres")
|
|
14069
|
-
built = sql`${ensureBuilt()} OR ${sql(String(column))} NOT ILIKE ${pattern}`;
|
|
14055
|
+
if (config5.dialect === "postgres")
|
|
14070
14056
|
addWhereText("OR", `${String(column)} NOT ILIKE ${ph}`);
|
|
14071
|
-
|
|
14072
|
-
const expr = sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14073
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14057
|
+
else
|
|
14074
14058
|
addWhereText("OR", `LOWER(${String(column)}) NOT LIKE LOWER(${ph})`);
|
|
14075
|
-
}
|
|
14076
14059
|
whereParams.push(pattern);
|
|
14060
|
+
built = null;
|
|
14077
14061
|
return this;
|
|
14078
14062
|
},
|
|
14079
14063
|
whereAny(cols, op, value) {
|
|
@@ -14673,19 +14657,21 @@ function createQueryBuilder(state) {
|
|
|
14673
14657
|
q = sql`${q} ORDER BY ${sql(String(column))} ${direction === "asc" ? sql`ASC` : sql`DESC`} LIMIT ${perPage + 1}`;
|
|
14674
14658
|
}
|
|
14675
14659
|
const rows = await runWithHooks(q, "select", { signal: abortSignal, timeoutMs });
|
|
14676
|
-
const
|
|
14660
|
+
const hasMore = rows.length > perPage;
|
|
14677
14661
|
const data = rows.slice(0, perPage);
|
|
14662
|
+
const lastRow = data[data.length - 1];
|
|
14663
|
+
const next = hasMore && lastRow ? Array.isArray(column) ? column.map((c) => lastRow[c]) : lastRow[column] : null;
|
|
14678
14664
|
const prevCursor = data.length ? Array.isArray(column) ? column.map((c) => data[0]?.[c]) : data[0]?.[column] : null;
|
|
14679
14665
|
return { data, meta: { perPage, nextCursor: next ?? null, prevCursor } };
|
|
14680
14666
|
},
|
|
14681
14667
|
async chunk(size, handler) {
|
|
14682
14668
|
let page = 1;
|
|
14683
14669
|
while (true) {
|
|
14684
|
-
const { data } = await this.paginate(size, page);
|
|
14670
|
+
const { data, meta: meta2 } = await this.paginate(size, page);
|
|
14685
14671
|
if (data.length === 0)
|
|
14686
14672
|
break;
|
|
14687
14673
|
await handler(data);
|
|
14688
|
-
if (
|
|
14674
|
+
if (page >= meta2.lastPage)
|
|
14689
14675
|
break;
|
|
14690
14676
|
page += 1;
|
|
14691
14677
|
}
|
|
@@ -30125,7 +30111,7 @@ function getPrefix() {
|
|
|
30125
30111
|
}
|
|
30126
30112
|
var prefix = getPrefix();
|
|
30127
30113
|
// package.json
|
|
30128
|
-
var version2 = "0.1.
|
|
30114
|
+
var version2 = "0.1.33";
|
|
30129
30115
|
|
|
30130
30116
|
// bin/cli.ts
|
|
30131
30117
|
init_actions();
|
package/dist/src/index.js
CHANGED
|
@@ -12835,7 +12835,7 @@ function createQueryBuilder(state) {
|
|
|
12835
12835
|
};
|
|
12836
12836
|
const addWhereText = (prefix, clause) => {
|
|
12837
12837
|
const hasWhere = SQL_PATTERNS.WHERE.test(text);
|
|
12838
|
-
const p = hasWhere ?
|
|
12838
|
+
const p = !hasWhere ? "WHERE" : prefix === "WHERE" ? "AND" : prefix;
|
|
12839
12839
|
text = `${text} ${p} ${clause}`;
|
|
12840
12840
|
};
|
|
12841
12841
|
const appendSetOp = (op, other) => {
|
|
@@ -13993,87 +13993,71 @@ function createQueryBuilder(state) {
|
|
|
13993
13993
|
return this;
|
|
13994
13994
|
},
|
|
13995
13995
|
whereLike(column, pattern, caseSensitive = false) {
|
|
13996
|
-
const expr = caseSensitive ? sql`${sql(String(column))} LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
13997
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
13998
13996
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
13999
13997
|
addWhereText("WHERE", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14000
13998
|
whereParams.push(pattern);
|
|
13999
|
+
built = null;
|
|
14001
14000
|
return this;
|
|
14002
14001
|
},
|
|
14003
14002
|
whereILike(column, pattern) {
|
|
14004
14003
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14005
|
-
if (config5.dialect === "postgres")
|
|
14006
|
-
built = sql`${ensureBuilt()} WHERE ${sql(String(column))} ILIKE ${pattern}`;
|
|
14004
|
+
if (config5.dialect === "postgres")
|
|
14007
14005
|
addWhereText("WHERE", `${String(column)} ILIKE ${ph}`);
|
|
14008
|
-
|
|
14009
|
-
const expr = sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
14010
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
14006
|
+
else
|
|
14011
14007
|
addWhereText("WHERE", `LOWER(${String(column)}) LIKE LOWER(${ph})`);
|
|
14012
|
-
}
|
|
14013
14008
|
whereParams.push(pattern);
|
|
14009
|
+
built = null;
|
|
14014
14010
|
return this;
|
|
14015
14011
|
},
|
|
14016
14012
|
orWhereLike(column, pattern, caseSensitive = false) {
|
|
14017
|
-
const expr = caseSensitive ? sql`${sql(String(column))} LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
14018
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14019
14013
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14020
14014
|
addWhereText("OR", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14021
14015
|
whereParams.push(pattern);
|
|
14016
|
+
built = null;
|
|
14022
14017
|
return this;
|
|
14023
14018
|
},
|
|
14024
14019
|
orWhereILike(column, pattern) {
|
|
14025
14020
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14026
|
-
if (config5.dialect === "postgres")
|
|
14027
|
-
built = sql`${ensureBuilt()} OR ${sql(String(column))} ILIKE ${pattern}`;
|
|
14021
|
+
if (config5.dialect === "postgres")
|
|
14028
14022
|
addWhereText("OR", `${String(column)} ILIKE ${ph}`);
|
|
14029
|
-
|
|
14030
|
-
const expr = sql`LOWER(${sql(String(column))}) LIKE LOWER(${pattern})`;
|
|
14031
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14023
|
+
else
|
|
14032
14024
|
addWhereText("OR", `LOWER(${String(column)}) LIKE LOWER(${ph})`);
|
|
14033
|
-
}
|
|
14034
14025
|
whereParams.push(pattern);
|
|
14026
|
+
built = null;
|
|
14035
14027
|
return this;
|
|
14036
14028
|
},
|
|
14037
14029
|
whereNotLike(column, pattern, caseSensitive = false) {
|
|
14038
|
-
const expr = caseSensitive ? sql`${sql(String(column))} NOT LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14039
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
14040
14030
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14041
14031
|
addWhereText("WHERE", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} NOT LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14042
14032
|
whereParams.push(pattern);
|
|
14033
|
+
built = null;
|
|
14043
14034
|
return this;
|
|
14044
14035
|
},
|
|
14045
14036
|
whereNotILike(column, pattern) {
|
|
14046
14037
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14047
|
-
if (config5.dialect === "postgres")
|
|
14048
|
-
built = sql`${ensureBuilt()} WHERE ${sql(String(column))} NOT ILIKE ${pattern}`;
|
|
14038
|
+
if (config5.dialect === "postgres")
|
|
14049
14039
|
addWhereText("WHERE", `${String(column)} NOT ILIKE ${ph}`);
|
|
14050
|
-
|
|
14051
|
-
const expr = sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14052
|
-
built = sql`${ensureBuilt()} WHERE ${expr}`;
|
|
14040
|
+
else
|
|
14053
14041
|
addWhereText("WHERE", `LOWER(${String(column)}) NOT LIKE LOWER(${ph})`);
|
|
14054
|
-
}
|
|
14055
14042
|
whereParams.push(pattern);
|
|
14043
|
+
built = null;
|
|
14056
14044
|
return this;
|
|
14057
14045
|
},
|
|
14058
14046
|
orWhereNotLike(column, pattern, caseSensitive = false) {
|
|
14059
|
-
const expr = caseSensitive ? sql`${sql(String(column))} NOT LIKE ${pattern}` : sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14060
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14061
14047
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14062
14048
|
addWhereText("OR", `${caseSensitive ? String(column) : `LOWER(${String(column)})`} NOT LIKE ${caseSensitive ? ph : `LOWER(${ph})`}`);
|
|
14063
14049
|
whereParams.push(pattern);
|
|
14050
|
+
built = null;
|
|
14064
14051
|
return this;
|
|
14065
14052
|
},
|
|
14066
14053
|
orWhereNotILike(column, pattern) {
|
|
14067
14054
|
const ph = getPlaceholder(whereParams.length + 1);
|
|
14068
|
-
if (config5.dialect === "postgres")
|
|
14069
|
-
built = sql`${ensureBuilt()} OR ${sql(String(column))} NOT ILIKE ${pattern}`;
|
|
14055
|
+
if (config5.dialect === "postgres")
|
|
14070
14056
|
addWhereText("OR", `${String(column)} NOT ILIKE ${ph}`);
|
|
14071
|
-
|
|
14072
|
-
const expr = sql`LOWER(${sql(String(column))}) NOT LIKE LOWER(${pattern})`;
|
|
14073
|
-
built = sql`${ensureBuilt()} OR ${expr}`;
|
|
14057
|
+
else
|
|
14074
14058
|
addWhereText("OR", `LOWER(${String(column)}) NOT LIKE LOWER(${ph})`);
|
|
14075
|
-
}
|
|
14076
14059
|
whereParams.push(pattern);
|
|
14060
|
+
built = null;
|
|
14077
14061
|
return this;
|
|
14078
14062
|
},
|
|
14079
14063
|
whereAny(cols, op, value) {
|
|
@@ -14673,19 +14657,21 @@ function createQueryBuilder(state) {
|
|
|
14673
14657
|
q = sql`${q} ORDER BY ${sql(String(column))} ${direction === "asc" ? sql`ASC` : sql`DESC`} LIMIT ${perPage + 1}`;
|
|
14674
14658
|
}
|
|
14675
14659
|
const rows = await runWithHooks(q, "select", { signal: abortSignal, timeoutMs });
|
|
14676
|
-
const
|
|
14660
|
+
const hasMore = rows.length > perPage;
|
|
14677
14661
|
const data = rows.slice(0, perPage);
|
|
14662
|
+
const lastRow = data[data.length - 1];
|
|
14663
|
+
const next = hasMore && lastRow ? Array.isArray(column) ? column.map((c) => lastRow[c]) : lastRow[column] : null;
|
|
14678
14664
|
const prevCursor = data.length ? Array.isArray(column) ? column.map((c) => data[0]?.[c]) : data[0]?.[column] : null;
|
|
14679
14665
|
return { data, meta: { perPage, nextCursor: next ?? null, prevCursor } };
|
|
14680
14666
|
},
|
|
14681
14667
|
async chunk(size, handler) {
|
|
14682
14668
|
let page = 1;
|
|
14683
14669
|
while (true) {
|
|
14684
|
-
const { data } = await this.paginate(size, page);
|
|
14670
|
+
const { data, meta: meta2 } = await this.paginate(size, page);
|
|
14685
14671
|
if (data.length === 0)
|
|
14686
14672
|
break;
|
|
14687
14673
|
await handler(data);
|
|
14688
|
-
if (
|
|
14674
|
+
if (page >= meta2.lastPage)
|
|
14689
14675
|
break;
|
|
14690
14676
|
page += 1;
|
|
14691
14677
|
}
|
package/package.json
CHANGED