@an5/orm 1.1.0 → 1.1.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.
@@ -289,7 +289,7 @@ func detectDialect(connStr string) Dialect {
289
289
  \tif strings.HasPrefix(l, "postgres://") || strings.HasPrefix(l, "postgresql://") || strings.Contains(l, "port=5432") {
290
290
  \t\treturn DialectPostgres
291
291
  \t}
292
- \tif strings.HasPrefix(l, "sqlite://") || strings.HasPrefix(l, "sqlite:") || strings.HasPrefix(l, "file:") || strings.HasSuffix(l, ".db") || strings.HasSuffix(l, ".sqlite") || strings.HasSuffix(l, ".sqlite3") || l == ":memory:" {
292
+ \tif l == "sqlite" || strings.HasPrefix(l, "sqlite://") || strings.HasPrefix(l, "sqlite:") || strings.HasPrefix(l, "file:") || strings.HasSuffix(l, ".db") || strings.HasSuffix(l, ".sqlite") || strings.HasSuffix(l, ".sqlite3") || l == ":memory:" {
293
293
  \t\treturn DialectSqlite
294
294
  \t}
295
295
  \treturn DialectMssql
@@ -363,6 +363,7 @@ func (c *TableClient[T]) quoteName(name string) string {
363
363
  // quoteTable quotes a schema.table name for the dialect.
364
364
  func (c *TableClient[T]) quoteTable() string {
365
365
  \tparts := strings.Split(c.TableName, ".")
366
+ \tif c.Dialect == DialectSqlite && len(parts) == 2 && strings.EqualFold(parts[0], "dbo") { parts = parts[1:] }
366
367
  \tquoted := make([]string, len(parts))
367
368
  \tfor i, p := range parts {
368
369
  \t\tquoted[i] = c.quoteName(p)
@@ -898,14 +899,14 @@ func (c *TableClient[T]) buildWhereFromStruct(v reflect.Value, argOffset int) (s
898
899
  \t\t\tvar subParts []string
899
900
  \t\t\tfor j := 0; j < fv.Len(); j++ {
900
901
  \t\t\t\tsub, subArgs := c.buildWhereFromStruct(fv.Index(j), argOffset+len(args))
901
- \t\t\t\tif sub != "" { subParts = append(subParts, sub); args = append(args, subArgs...) }
902
+ \t\t\t\tif sub == "" { sub = "1=1" }; subParts = append(subParts, sub); args = append(args, subArgs...)
902
903
  \t\t\t}
903
- \t\t\tif len(subParts) > 0 { parts = append(parts, "("+strings.Join(subParts, " OR ")+")") }
904
+ \t\t\tif len(subParts) > 0 { parts = append(parts, "("+strings.Join(subParts, " OR ")+")") } else { parts = append(parts, "1=0") }
904
905
  \t\t\tcontinue
905
906
  \t\t}
906
907
  \t\tif name == "NOT" && fv.Kind() == reflect.Ptr && !fv.IsNil() {
907
908
  \t\t\tsub, subArgs := c.buildWhereFromStruct(fv.Elem(), argOffset+len(args))
908
- \t\t\tif sub != "" { parts = append(parts, "NOT ("+sub+")"); args = append(args, subArgs...) }
909
+ \t\t\tif sub == "" { sub = "1=1" }; parts = append(parts, "NOT ("+sub+")"); args = append(args, subArgs...)
909
910
  \t\t\tcontinue
910
911
  \t\t}
911
912
 
package/dist/sql-utils.js CHANGED
@@ -119,12 +119,17 @@ function parseWhere(modelName, where, params, prefix = "", ctx = {}) {
119
119
  }
120
120
  }
121
121
  for (const [key, value] of Object.entries(cleanWhere)) {
122
+ if (value === undefined)
123
+ continue;
122
124
  if (key === "OR" && Array.isArray(value)) {
123
- const orConditions = value.map((subWhere, idx) => parseWhere(modelName, subWhere, params, `${prefix}or_${idx}_`, ctx));
125
+ const orConditions = value.map((subWhere, idx) => parseWhere(modelName, subWhere, params, `${prefix}or_${idx}_`, ctx) || "1=1");
124
126
  const filtered = orConditions.filter(Boolean);
125
127
  if (filtered.length > 0) {
126
128
  conditions.push(`(${filtered.join(" OR ")})`);
127
129
  }
130
+ else {
131
+ conditions.push("1=0");
132
+ }
128
133
  }
129
134
  else if (key === "AND") {
130
135
  const andItems = Array.isArray(value) ? value : [value];
@@ -136,10 +141,10 @@ function parseWhere(modelName, where, params, prefix = "", ctx = {}) {
136
141
  }
137
142
  else if (key === "NOT") {
138
143
  const notItems = Array.isArray(value) ? value : [value];
139
- const notConditions = notItems.map((subWhere, idx) => parseWhere(modelName, subWhere, params, `${prefix}not_${idx}_`, ctx));
144
+ const notConditions = notItems.map((subWhere, idx) => parseWhere(modelName, subWhere, params, `${prefix}not_${idx}_`, ctx) || "1=1");
140
145
  const filtered = notConditions.filter(Boolean);
141
146
  if (filtered.length > 0) {
142
- conditions.push(`NOT (${filtered.join(" AND ")})`);
147
+ conditions.push(`NOT (${filtered.join(" OR ")})`);
143
148
  }
144
149
  }
145
150
  else {
@@ -296,7 +296,7 @@ func detectDialect(connStr string) Dialect {
296
296
  \tif strings.HasPrefix(l, "postgres://") || strings.HasPrefix(l, "postgresql://") || strings.Contains(l, "port=5432") {
297
297
  \t\treturn DialectPostgres
298
298
  \t}
299
- \tif strings.HasPrefix(l, "sqlite://") || strings.HasPrefix(l, "sqlite:") || strings.HasPrefix(l, "file:") || strings.HasSuffix(l, ".db") || strings.HasSuffix(l, ".sqlite") || strings.HasSuffix(l, ".sqlite3") || l == ":memory:" {
299
+ \tif l == "sqlite" || strings.HasPrefix(l, "sqlite://") || strings.HasPrefix(l, "sqlite:") || strings.HasPrefix(l, "file:") || strings.HasSuffix(l, ".db") || strings.HasSuffix(l, ".sqlite") || strings.HasSuffix(l, ".sqlite3") || l == ":memory:" {
300
300
  \t\treturn DialectSqlite
301
301
  \t}
302
302
  \treturn DialectMssql
@@ -377,6 +377,7 @@ func (c *TableClient[T]) quoteName(name string) string {
377
377
  // quoteTable quotes a schema.table name for the dialect.
378
378
  func (c *TableClient[T]) quoteTable() string {
379
379
  \tparts := strings.Split(c.TableName, ".")
380
+ \tif c.Dialect == DialectSqlite && len(parts) == 2 && strings.EqualFold(parts[0], "dbo") { parts = parts[1:] }
380
381
  \tquoted := make([]string, len(parts))
381
382
  \tfor i, p := range parts {
382
383
  \t\tquoted[i] = c.quoteName(p)
@@ -918,14 +919,14 @@ func (c *TableClient[T]) buildWhereFromStruct(v reflect.Value, argOffset int) (s
918
919
  \t\t\tvar subParts []string
919
920
  \t\t\tfor j := 0; j < fv.Len(); j++ {
920
921
  \t\t\t\tsub, subArgs := c.buildWhereFromStruct(fv.Index(j), argOffset+len(args))
921
- \t\t\t\tif sub != "" { subParts = append(subParts, sub); args = append(args, subArgs...) }
922
+ \t\t\t\tif sub == "" { sub = "1=1" }; subParts = append(subParts, sub); args = append(args, subArgs...)
922
923
  \t\t\t}
923
- \t\t\tif len(subParts) > 0 { parts = append(parts, "("+strings.Join(subParts, " OR ")+")") }
924
+ \t\t\tif len(subParts) > 0 { parts = append(parts, "("+strings.Join(subParts, " OR ")+")") } else { parts = append(parts, "1=0") }
924
925
  \t\t\tcontinue
925
926
  \t\t}
926
927
  \t\tif name == "NOT" && fv.Kind() == reflect.Ptr && !fv.IsNil() {
927
928
  \t\t\tsub, subArgs := c.buildWhereFromStruct(fv.Elem(), argOffset+len(args))
928
- \t\t\tif sub != "" { parts = append(parts, "NOT ("+sub+")"); args = append(args, subArgs...) }
929
+ \t\t\tif sub == "" { sub = "1=1" }; parts = append(parts, "NOT ("+sub+")"); args = append(args, subArgs...)
929
930
  \t\t\tcontinue
930
931
  \t\t}
931
932
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@an5/orm",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "The lightweight ORM for SQL Server with support for TypeScript, Python, .NET (C#), Go, and Rust.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -47,7 +47,7 @@
47
47
  "db:migrate:status": "npx tsx migrate.ts status",
48
48
  "release:cli": "npx tsx scripts/release-cli.ts",
49
49
  "release": "node scripts/release.js",
50
- "test": "npm run typecheck:cli && node test/smoke.test.js && node test/unit.test.js && node test/generator-regressions.test.js && node --test test/config.test.js && node --test test/provider-types.test.js && node --test test/provider-push.test.js && node --test test/provider-push.sqlite.test.js && node --test test/type-kinds.test.js && node --test test/declarations.test.js && node --test test/version-sync.test.js",
50
+ "test": "npm run typecheck:cli && node test/smoke.test.js && node test/unit.test.js && node test/generator-regressions.test.js && node --test test/config.test.js && node --test test/provider-types.test.js && node --test test/provider-push.test.js && node --test test/provider-push.sqlite.test.js && node --test test/type-kinds.test.js && node --test test/declarations.test.js && node --test test/version-sync.test.js && node --test test/query-semantics.test.js",
51
51
  "test:unit": "node test/unit.test.js",
52
52
  "test:generator": "npm run generate && node test/generator.test.js",
53
53
  "test:generator:regressions": "node test/generator-regressions.test.js",