bun-types 1.1.14-canary.20240616T140455 → 1.1.14-canary.20240618T140456

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/sqlite.d.ts +92 -3
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.14-canary.20240616T140455",
2
+ "version": "1.1.14-canary.20240618T140456",
3
3
  "name": "bun-types",
4
4
  "license": "MIT",
5
5
  "main": "",
package/sqlite.d.ts CHANGED
@@ -82,6 +82,40 @@ declare module "bun:sqlite" {
82
82
  * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
83
83
  */
84
84
  readwrite?: boolean;
85
+
86
+ /**
87
+ * When set to `true`, integers are returned as `bigint` types.
88
+ *
89
+ * When set to `false`, integers are returned as `number` types and truncated to 52 bits.
90
+ *
91
+ * @default false
92
+ * @since v1.1.14
93
+ */
94
+ safeInteger?: boolean;
95
+
96
+ /**
97
+ * When set to `false` or `undefined`:
98
+ * - Queries missing bound parameters will NOT throw an error
99
+ * - Bound named parameters in JavaScript need to exactly match the SQL query.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const db = new Database(":memory:", { strict: false });
104
+ * db.run("INSERT INTO foo (name) VALUES ($name)", { $name: "foo" });
105
+ * ```
106
+ *
107
+ * When set to `true`:
108
+ * - Queries missing bound parameters will throw an error
109
+ * - Bound named parameters in JavaScript no longer need to be `$`, `:`, or `@`. The SQL query will remain prefixed.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const db = new Database(":memory:", { strict: true });
114
+ * db.run("INSERT INTO foo (name) VALUES ($name)", { name: "foo" });
115
+ * ```
116
+ * @since v1.1.14
117
+ */
118
+ strict?: boolean;
85
119
  },
86
120
  );
87
121
 
@@ -168,14 +202,14 @@ declare module "bun:sqlite" {
168
202
  run<ParamsType extends SQLQueryBindings[]>(
169
203
  sqlQuery: string,
170
204
  ...bindings: ParamsType[]
171
- ): void;
205
+ ): Changes;
172
206
  /**
173
207
  This is an alias of {@link Database.prototype.run}
174
208
  */
175
209
  exec<ParamsType extends SQLQueryBindings[]>(
176
210
  sqlQuery: string,
177
211
  ...bindings: ParamsType[]
178
- ): void;
212
+ ): Changes;
179
213
 
180
214
  /**
181
215
  * Compile a SQL query and return a {@link Statement} object. This is the
@@ -595,7 +629,7 @@ declare module "bun:sqlite" {
595
629
  * | `bigint` | `INTEGER` |
596
630
  * | `null` | `NULL` |
597
631
  */
598
- run(...params: ParamsType): void;
632
+ run(...params: ParamsType): Changes;
599
633
 
600
634
  /**
601
635
  * Execute the prepared statement and return the results as an array of arrays.
@@ -702,6 +736,44 @@ declare module "bun:sqlite" {
702
736
  */
703
737
  toString(): string;
704
738
 
739
+ /**
740
+ *
741
+ * Make {@link get} and {@link all} return an instance of the provided
742
+ * `Class` instead of the default `Object`.
743
+ *
744
+ * @param Class A class to use
745
+ * @returns The same statement instance, modified to return an instance of `Class`
746
+ *
747
+ * This lets you attach methods, getters, and setters to the returned
748
+ * objects.
749
+ *
750
+ * For performance reasons, constructors for classes are not called, which means
751
+ * initializers will not be called and private fields will not be
752
+ * accessible.
753
+ *
754
+ * @example
755
+ *
756
+ * ## Custom class
757
+ * ```ts
758
+ * class User {
759
+ * rawBirthdate: string;
760
+ * get birthdate() {
761
+ * return new Date(this.rawBirthdate);
762
+ * }
763
+ * }
764
+ *
765
+ * const db = new Database(":memory:");
766
+ * db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, rawBirthdate TEXT)");
767
+ * db.run("INSERT INTO users (rawBirthdate) VALUES ('1995-12-19')");
768
+ * const query = db.query("SELECT * FROM users");
769
+ * query.as(User);
770
+ * const user = query.get();
771
+ * console.log(user.birthdate);
772
+ * // => Date(1995, 11, 19)
773
+ * ```
774
+ */
775
+ as<T = unknown>(Class: new (...args: any[]) => T): Statement<T, ParamsType>;
776
+
705
777
  /**
706
778
  * Native object representing the underlying `sqlite3_stmt`
707
779
  *
@@ -1065,4 +1137,21 @@ declare module "bun:sqlite" {
1065
1137
  */
1066
1138
  readonly byteOffset: number;
1067
1139
  }
1140
+
1141
+ /**
1142
+ * An object representing the changes made to the database since the last `run` or `exec` call.
1143
+ *
1144
+ * @since Bun v1.1.14
1145
+ */
1146
+ interface Changes {
1147
+ /**
1148
+ * The number of rows changed by the last `run` or `exec` call.
1149
+ */
1150
+ changes: number;
1151
+
1152
+ /**
1153
+ * If `safeIntegers` is `true`, this is a `bigint`. Otherwise, it is a `number`.
1154
+ */
1155
+ lastInsertRowid: number | bigint;
1156
+ }
1068
1157
  }