weifuwu 0.93.0 → 0.93.1

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.
@@ -3900,12 +3900,14 @@ function compileWhere(expr, params) {
3900
3900
  for (const [col, field] of Object.entries(expr)) {
3901
3901
  if (col === "or") {
3902
3902
  const ors = field;
3903
- parts.push(`(${ors.map((o) => compileWhere(o, params)).join(" OR ")})`);
3903
+ const sub = ors.map((o) => compileWhere(o, params)).filter((s) => s !== "");
3904
+ parts.push(sub.length ? `(${sub.join(" OR ")})` : "");
3904
3905
  continue;
3905
3906
  }
3906
3907
  if (col === "and") {
3907
3908
  const ands = field;
3908
- parts.push(`(${ands.map((o) => compileWhere(o, params)).join(" AND ")})`);
3909
+ const sub = ands.map((o) => compileWhere(o, params)).filter((s) => s !== "");
3910
+ parts.push(sub.length ? `(${sub.join(" AND ")})` : "");
3909
3911
  continue;
3910
3912
  }
3911
3913
  if (typeof field === "object" && field !== null) {
@@ -3947,7 +3949,7 @@ function compileWhere(expr, params) {
3947
3949
  }
3948
3950
  throw new ProtocolError(`weifuwu/db: WHERE \u5217 ${col} \u503C\u5FC5\u987B\u4E3A\u7B97\u5B50\u5BF9\u8C61\uFF08{ eq: v } / { in: [...] } / { isNull: true }\u2014\u2014\u88F8\u6807\u91CF/\u6570\u7EC4/null \u5F62\u6001\u5DF2\u79FB\u9664\uFF09`);
3949
3951
  }
3950
- return parts.join(" AND ");
3952
+ return parts.filter((s) => s !== "").join(" AND ");
3951
3953
  }
3952
3954
  function compileOrderBy(orderBy) {
3953
3955
  if (!orderBy?.length) return "";
@@ -3972,9 +3974,12 @@ function compileSelect(q) {
3972
3974
  let sql = `SELECT ${distinct}${cols2}${agg} FROM ${q.table}${q.alias ? ` ${q.alias}` : ""}`;
3973
3975
  for (const j of q.joins ?? []) {
3974
3976
  const on = isRaw(j.on) ? interpRaw(j.on, params) : compileWhere(j.on, params);
3975
- sql += ` ${j.type === "left" ? "LEFT JOIN" : "JOIN"} ${j.table}${j.alias ? ` ${j.alias}` : ""} ON ${on}`;
3977
+ sql += ` ${j.type === "left" ? "LEFT JOIN" : "JOIN"} ${j.table}${j.alias ? ` ${j.alias}` : ""} ON ${on || "(1=1)"}`;
3978
+ }
3979
+ {
3980
+ const w = q.where ? compileWhere(q.where, params) : "";
3981
+ if (w) sql += ` WHERE ${w}`;
3976
3982
  }
3977
- if (q.where) sql += ` WHERE ${compileWhere(q.where, params)}`;
3978
3983
  for (const s of q.sub ?? []) {
3979
3984
  const sub = compileSelect(s.query);
3980
3985
  const base = params.length + 1;
@@ -4031,7 +4036,11 @@ function compileUpdate(q) {
4031
4036
  if (!q.where) throw new ValidationError("weifuwu/db: UPDATE \u5FC5\u987B\u5E26 WHERE\uFF08\u5168\u8868\u66F4\u65B0\u7528 orm.execute \u663E\u5F0F\uFF09");
4032
4037
  const setSql = Object.entries(q.sets).map(([col, v]) => `${col} = ${compileMergeVal(col, v, params, q.table)}`).join(", ");
4033
4038
  let sql = `UPDATE ${q.table} SET ${setSql}`;
4034
- if (q.where) sql += ` WHERE ${compileWhere(q.where, params)}`;
4039
+ {
4040
+ const w = compileWhere(q.where, params);
4041
+ if (!w) throw new ValidationError("weifuwu/db: UPDATE \u6761\u4EF6\u4E3A\u7A7A\uFF08\u7A7A\u5BF9\u8C61/\u7A7A and \u7EC4 = \u5168\u8868\u66F4\u65B0\u2014\u2014\u663E\u5F0F\u62D2\u7EDD\uFF09");
4042
+ sql += ` WHERE ${w}`;
4043
+ }
4035
4044
  if (q.returning) {
4036
4045
  const r = q.returning === "*" ? "*" : q.returning.join(", ");
4037
4046
  sql += ` RETURNING ${r}`;
@@ -4042,7 +4051,11 @@ function compileDelete(q) {
4042
4051
  const params = [];
4043
4052
  if (!q.where) throw new ValidationError("weifuwu/db: DELETE \u5FC5\u987B\u5E26 WHERE\uFF08\u5168\u8868\u5220\u9664\u7528 orm.execute \u663E\u5F0F\uFF09");
4044
4053
  let sql = `DELETE FROM ${q.table}`;
4045
- if (q.where) sql += ` WHERE ${compileWhere(q.where, params)}`;
4054
+ {
4055
+ const w = compileWhere(q.where, params);
4056
+ if (!w) throw new ValidationError("weifuwu/db: DELETE \u6761\u4EF6\u4E3A\u7A7A\uFF08\u7A7A\u5BF9\u8C61/\u7A7A and \u7EC4 = \u5168\u8868\u5220\u9664\u2014\u2014\u663E\u5F0F\u62D2\u7EDD\uFF09");
4057
+ sql += ` WHERE ${w}`;
4058
+ }
4046
4059
  if (q.returning) {
4047
4060
  const r = q.returning === "*" ? "*" : q.returning.join(", ");
4048
4061
  sql += ` RETURNING ${r}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weifuwu",
3
3
  "type": "module",
4
- "version": "0.93.0",
4
+ "version": "0.93.1",
5
5
  "description": "AI SaaS full-stack framework — backend HTTP + frontend VDOM + 129 components + CSS design system + SaaS foundation (auth/queue/AI). Zero-build, zero-dependency.",
6
6
  "exports": {
7
7
  ".": {