@type32/tauri-sqlite-orm 0.2.12 → 0.2.13

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/index.js CHANGED
@@ -529,9 +529,15 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
529
529
  async execute() {
530
530
  const { sql: joinSql, params: joinParams } = this.buildJoins();
531
531
  const distinct = this.isDistinct ? "DISTINCT " : "";
532
- this.query = `SELECT ${distinct}${this.selectedColumns.join(", ")} ${this.query}`;
533
- this.query += joinSql;
534
- this.params.push(...joinParams);
532
+ const whereIndex = this.query.indexOf(" WHERE ");
533
+ let fromPart = this.query;
534
+ let wherePart = "";
535
+ if (whereIndex !== -1) {
536
+ fromPart = this.query.substring(0, whereIndex);
537
+ wherePart = this.query.substring(whereIndex);
538
+ }
539
+ this.query = `SELECT ${distinct}${this.selectedColumns.join(", ")} ${fromPart}${joinSql}${wherePart}`;
540
+ this.params = [...joinParams, ...this.params];
535
541
  const { sql: sql2, params } = this.build();
536
542
  const rawResults = await this.db.select(sql2, params);
537
543
  const hasIncludes = Object.values(this.includeRelations).some((i) => i);
@@ -706,8 +712,15 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
706
712
  const originalColumns = this.selectedColumns;
707
713
  this.selectedColumns = ["1"];
708
714
  const { sql: joinSql, params: joinParams } = this.buildJoins();
709
- const query = `SELECT 1 ${this.query}${joinSql} LIMIT 1`;
710
- const params = [...this.params, ...joinParams];
715
+ const whereIndex = this.query.indexOf(" WHERE ");
716
+ let fromPart = this.query;
717
+ let wherePart = "";
718
+ if (whereIndex !== -1) {
719
+ fromPart = this.query.substring(0, whereIndex);
720
+ wherePart = this.query.substring(whereIndex);
721
+ }
722
+ const query = `SELECT 1 ${fromPart}${joinSql}${wherePart} LIMIT 1`;
723
+ const params = [...joinParams, ...this.params];
711
724
  this.selectedColumns = originalColumns;
712
725
  const result = await this.db.select(query, params);
713
726
  return result.length > 0;
@@ -716,8 +729,15 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
716
729
  const originalColumns = this.selectedColumns;
717
730
  this.selectedColumns = ["COUNT(*) as count"];
718
731
  const { sql: joinSql, params: joinParams } = this.buildJoins();
719
- const query = `SELECT COUNT(*) as count ${this.query}${joinSql}`;
720
- const params = [...this.params, ...joinParams];
732
+ const whereIndex = this.query.indexOf(" WHERE ");
733
+ let fromPart = this.query;
734
+ let wherePart = "";
735
+ if (whereIndex !== -1) {
736
+ fromPart = this.query.substring(0, whereIndex);
737
+ wherePart = this.query.substring(whereIndex);
738
+ }
739
+ const query = `SELECT COUNT(*) as count ${fromPart}${joinSql}${wherePart}`;
740
+ const params = [...joinParams, ...this.params];
721
741
  this.selectedColumns = originalColumns;
722
742
  const result = await this.db.select(query, params);
723
743
  return result[0]?.count || 0;
@@ -730,11 +750,19 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
730
750
  const originalColumns = this.selectedColumns;
731
751
  this.selectedColumns = [`${this.selectedTableAlias}.${columnName} AS "${columnName}"`];
732
752
  const { sql: joinSql, params: joinParams } = this.buildJoins();
733
- const query = `SELECT ${this.selectedColumns.join(", ")} ${this.query}${joinSql}`;
734
- const params = [...this.params, ...joinParams];
753
+ const whereIndex = this.query.indexOf(" WHERE ");
754
+ let fromPart = this.query;
755
+ let wherePart = "";
756
+ if (whereIndex !== -1) {
757
+ fromPart = this.query.substring(0, whereIndex);
758
+ wherePart = this.query.substring(whereIndex);
759
+ }
760
+ const query = `SELECT ${this.selectedColumns.join(", ")} ${fromPart}${joinSql}${wherePart}`;
761
+ const params = [...joinParams, ...this.params];
735
762
  this.selectedColumns = originalColumns;
736
763
  const results = await this.db.select(query, params);
737
- return results.map((row) => row[columnName]);
764
+ const col = this.table._.columns[column];
765
+ return results.map((row) => col ? deserializeValue(row[columnName], col) : row[columnName]);
738
766
  }
739
767
  async paginate(page = 1, pageSize = 10) {
740
768
  if (page < 1) page = 1;
package/dist/index.mjs CHANGED
@@ -430,9 +430,15 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
430
430
  async execute() {
431
431
  const { sql: joinSql, params: joinParams } = this.buildJoins();
432
432
  const distinct = this.isDistinct ? "DISTINCT " : "";
433
- this.query = `SELECT ${distinct}${this.selectedColumns.join(", ")} ${this.query}`;
434
- this.query += joinSql;
435
- this.params.push(...joinParams);
433
+ const whereIndex = this.query.indexOf(" WHERE ");
434
+ let fromPart = this.query;
435
+ let wherePart = "";
436
+ if (whereIndex !== -1) {
437
+ fromPart = this.query.substring(0, whereIndex);
438
+ wherePart = this.query.substring(whereIndex);
439
+ }
440
+ this.query = `SELECT ${distinct}${this.selectedColumns.join(", ")} ${fromPart}${joinSql}${wherePart}`;
441
+ this.params = [...joinParams, ...this.params];
436
442
  const { sql: sql2, params } = this.build();
437
443
  const rawResults = await this.db.select(sql2, params);
438
444
  const hasIncludes = Object.values(this.includeRelations).some((i) => i);
@@ -607,8 +613,15 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
607
613
  const originalColumns = this.selectedColumns;
608
614
  this.selectedColumns = ["1"];
609
615
  const { sql: joinSql, params: joinParams } = this.buildJoins();
610
- const query = `SELECT 1 ${this.query}${joinSql} LIMIT 1`;
611
- const params = [...this.params, ...joinParams];
616
+ const whereIndex = this.query.indexOf(" WHERE ");
617
+ let fromPart = this.query;
618
+ let wherePart = "";
619
+ if (whereIndex !== -1) {
620
+ fromPart = this.query.substring(0, whereIndex);
621
+ wherePart = this.query.substring(whereIndex);
622
+ }
623
+ const query = `SELECT 1 ${fromPart}${joinSql}${wherePart} LIMIT 1`;
624
+ const params = [...joinParams, ...this.params];
612
625
  this.selectedColumns = originalColumns;
613
626
  const result = await this.db.select(query, params);
614
627
  return result.length > 0;
@@ -617,8 +630,15 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
617
630
  const originalColumns = this.selectedColumns;
618
631
  this.selectedColumns = ["COUNT(*) as count"];
619
632
  const { sql: joinSql, params: joinParams } = this.buildJoins();
620
- const query = `SELECT COUNT(*) as count ${this.query}${joinSql}`;
621
- const params = [...this.params, ...joinParams];
633
+ const whereIndex = this.query.indexOf(" WHERE ");
634
+ let fromPart = this.query;
635
+ let wherePart = "";
636
+ if (whereIndex !== -1) {
637
+ fromPart = this.query.substring(0, whereIndex);
638
+ wherePart = this.query.substring(whereIndex);
639
+ }
640
+ const query = `SELECT COUNT(*) as count ${fromPart}${joinSql}${wherePart}`;
641
+ const params = [...joinParams, ...this.params];
622
642
  this.selectedColumns = originalColumns;
623
643
  const result = await this.db.select(query, params);
624
644
  return result[0]?.count || 0;
@@ -631,11 +651,19 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
631
651
  const originalColumns = this.selectedColumns;
632
652
  this.selectedColumns = [`${this.selectedTableAlias}.${columnName} AS "${columnName}"`];
633
653
  const { sql: joinSql, params: joinParams } = this.buildJoins();
634
- const query = `SELECT ${this.selectedColumns.join(", ")} ${this.query}${joinSql}`;
635
- const params = [...this.params, ...joinParams];
654
+ const whereIndex = this.query.indexOf(" WHERE ");
655
+ let fromPart = this.query;
656
+ let wherePart = "";
657
+ if (whereIndex !== -1) {
658
+ fromPart = this.query.substring(0, whereIndex);
659
+ wherePart = this.query.substring(whereIndex);
660
+ }
661
+ const query = `SELECT ${this.selectedColumns.join(", ")} ${fromPart}${joinSql}${wherePart}`;
662
+ const params = [...joinParams, ...this.params];
636
663
  this.selectedColumns = originalColumns;
637
664
  const results = await this.db.select(query, params);
638
- return results.map((row) => row[columnName]);
665
+ const col = this.table._.columns[column];
666
+ return results.map((row) => col ? deserializeValue(row[columnName], col) : row[columnName]);
639
667
  }
640
668
  async paginate(page = 1, pageSize = 10) {
641
669
  if (page < 1) page = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type32/tauri-sqlite-orm",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "A Drizzle-like ORM for Tauri v2's SQL JS API plugin.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",