@tursodatabase/database 0.1.4-pre.9 → 0.1.4

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.
@@ -27,6 +27,7 @@ class Database {
27
27
  db;
28
28
  memory;
29
29
  open;
30
+ _inTransaction = false;
30
31
  /**
31
32
  * Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
32
33
  *
@@ -47,9 +48,7 @@ class Database {
47
48
  const db = this.db;
48
49
  Object.defineProperties(this, {
49
50
  inTransaction: {
50
- get() {
51
- throw new Error("not implemented");
52
- },
51
+ get: () => this._inTransaction,
53
52
  },
54
53
  name: {
55
54
  get() {
@@ -99,13 +98,16 @@ class Database {
99
98
  const wrapTxn = (mode) => {
100
99
  return (...bindParameters) => {
101
100
  db.exec("BEGIN " + mode);
101
+ db._inTransaction = true;
102
102
  try {
103
103
  const result = fn(...bindParameters);
104
104
  db.exec("COMMIT");
105
+ db._inTransaction = false;
105
106
  return result;
106
107
  }
107
108
  catch (err) {
108
109
  db.exec("ROLLBACK");
110
+ db._inTransaction = false;
109
111
  throw err;
110
112
  }
111
113
  };
@@ -178,6 +180,14 @@ class Database {
178
180
  interrupt() {
179
181
  throw new Error("not implemented");
180
182
  }
183
+ /**
184
+ * Sets the default safe integers mode for all statements from this database.
185
+ *
186
+ * @param {boolean} [toggle] - Whether to use safe integers by default.
187
+ */
188
+ defaultSafeIntegers(toggle) {
189
+ this.db.defaultSafeIntegers(toggle);
190
+ }
181
191
  /**
182
192
  * Closes the database connection.
183
193
  */
@@ -213,6 +223,23 @@ class Statement {
213
223
  this.stmt.pluck(pluckMode);
214
224
  return this;
215
225
  }
226
+ /**
227
+ * Sets safe integers mode for this statement.
228
+ *
229
+ * @param {boolean} [toggle] - Whether to use safe integers.
230
+ */
231
+ safeIntegers(toggle) {
232
+ this.stmt.safeIntegers(toggle);
233
+ return this;
234
+ }
235
+ /**
236
+ * Get column information for the statement.
237
+ *
238
+ * @returns {Array} An array of column objects with name, column, table, database, and type properties.
239
+ */
240
+ columns() {
241
+ return this.stmt.columns();
242
+ }
216
243
  get source() {
217
244
  throw new Error("not implemented");
218
245
  }
@@ -321,12 +348,6 @@ class Statement {
321
348
  interrupt() {
322
349
  throw new Error("not implemented");
323
350
  }
324
- /**
325
- * Returns the columns in the result set returned by this prepared statement.
326
- */
327
- columns() {
328
- throw new Error("not implemented");
329
- }
330
351
  /**
331
352
  * Binds the given parameters to the statement _permanently_
332
353
  *
package/dist/promise.js CHANGED
@@ -27,6 +27,7 @@ class Database {
27
27
  db;
28
28
  memory;
29
29
  open;
30
+ _inTransaction = false;
30
31
  /**
31
32
  * Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
32
33
  *
@@ -53,9 +54,7 @@ class Database {
53
54
  this.memory = db.memory;
54
55
  Object.defineProperties(this, {
55
56
  inTransaction: {
56
- get() {
57
- throw new Error("not implemented");
58
- },
57
+ get: () => this._inTransaction,
59
58
  },
60
59
  name: {
61
60
  get() {
@@ -105,13 +104,16 @@ class Database {
105
104
  const wrapTxn = (mode) => {
106
105
  return (...bindParameters) => {
107
106
  db.exec("BEGIN " + mode);
107
+ db._inTransaction = true;
108
108
  try {
109
109
  const result = fn(...bindParameters);
110
110
  db.exec("COMMIT");
111
+ db._inTransaction = false;
111
112
  return result;
112
113
  }
113
114
  catch (err) {
114
115
  db.exec("ROLLBACK");
116
+ db._inTransaction = false;
115
117
  throw err;
116
118
  }
117
119
  };
@@ -184,6 +186,14 @@ class Database {
184
186
  interrupt() {
185
187
  throw new Error("not implemented");
186
188
  }
189
+ /**
190
+ * Sets the default safe integers mode for all statements from this database.
191
+ *
192
+ * @param {boolean} [toggle] - Whether to use safe integers by default.
193
+ */
194
+ defaultSafeIntegers(toggle) {
195
+ this.db.defaultSafeIntegers(toggle);
196
+ }
187
197
  /**
188
198
  * Closes the database connection.
189
199
  */
@@ -219,6 +229,23 @@ class Statement {
219
229
  this.stmt.pluck(pluckMode);
220
230
  return this;
221
231
  }
232
+ /**
233
+ * Sets safe integers mode for this statement.
234
+ *
235
+ * @param {boolean} [toggle] - Whether to use safe integers.
236
+ */
237
+ safeIntegers(toggle) {
238
+ this.stmt.safeIntegers(toggle);
239
+ return this;
240
+ }
241
+ /**
242
+ * Get column information for the statement.
243
+ *
244
+ * @returns {Array} An array of column objects with name, column, table, database, and type properties.
245
+ */
246
+ columns() {
247
+ return this.stmt.columns();
248
+ }
222
249
  get source() {
223
250
  throw new Error("not implemented");
224
251
  }
@@ -327,12 +354,6 @@ class Statement {
327
354
  interrupt() {
328
355
  throw new Error("not implemented");
329
356
  }
330
- /**
331
- * Returns the columns in the result set returned by this prepared statement.
332
- */
333
- columns() {
334
- throw new Error("not implemented");
335
- }
336
357
  /**
337
358
  * Binds the given parameters to the statement _permanently_
338
359
  *
package/index.d.ts ADDED
@@ -0,0 +1,130 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ /** A database connection. */
4
+ export declare class Database {
5
+ /**
6
+ * Creates a new database instance.
7
+ *
8
+ * # Arguments
9
+ * * `path` - The path to the database file.
10
+ */
11
+ constructor(path: string)
12
+ /** Returns whether the database is in memory-only mode. */
13
+ get memory(): boolean
14
+ /** Returns whether the database connection is open. */
15
+ get open(): boolean
16
+ /**
17
+ * Executes a batch of SQL statements.
18
+ *
19
+ * # Arguments
20
+ *
21
+ * * `sql` - The SQL statements to execute.
22
+ *
23
+ * # Returns
24
+ */
25
+ batch(sql: string): void
26
+ /**
27
+ * Prepares a statement for execution.
28
+ *
29
+ * # Arguments
30
+ *
31
+ * * `sql` - The SQL statement to prepare.
32
+ *
33
+ * # Returns
34
+ *
35
+ * A `Statement` instance.
36
+ */
37
+ prepare(sql: string): Statement
38
+ /**
39
+ * Returns the rowid of the last row inserted.
40
+ *
41
+ * # Returns
42
+ *
43
+ * The rowid of the last row inserted.
44
+ */
45
+ lastInsertRowid(): number
46
+ /**
47
+ * Returns the number of changes made by the last statement.
48
+ *
49
+ * # Returns
50
+ *
51
+ * The number of changes made by the last statement.
52
+ */
53
+ changes(): number
54
+ /**
55
+ * Returns the total number of changes made by all statements.
56
+ *
57
+ * # Returns
58
+ *
59
+ * The total number of changes made by all statements.
60
+ */
61
+ totalChanges(): number
62
+ /**
63
+ * Closes the database connection.
64
+ *
65
+ * # Returns
66
+ *
67
+ * `Ok(())` if the database is closed successfully.
68
+ */
69
+ close(): void
70
+ /**
71
+ * Sets the default safe integers mode for all statements from this database.
72
+ *
73
+ * # Arguments
74
+ *
75
+ * * `toggle` - Whether to use safe integers by default.
76
+ */
77
+ defaultSafeIntegers(toggle?: boolean | undefined | null): void
78
+ /** Runs the I/O loop synchronously. */
79
+ ioLoopSync(): void
80
+ /** Runs the I/O loop asynchronously, returning a Promise. */
81
+ ioLoopAsync(): Promise<void>
82
+ }
83
+
84
+ /** A prepared statement. */
85
+ export declare class Statement {
86
+ reset(): void
87
+ /** Returns the number of parameters in the statement. */
88
+ parameterCount(): number
89
+ /**
90
+ * Returns the name of a parameter at a specific 1-based index.
91
+ *
92
+ * # Arguments
93
+ *
94
+ * * `index` - The 1-based parameter index.
95
+ */
96
+ parameterName(index: number): string | null
97
+ /**
98
+ * Binds a parameter at a specific 1-based index with explicit type.
99
+ *
100
+ * # Arguments
101
+ *
102
+ * * `index` - The 1-based parameter index.
103
+ * * `value_type` - The type constant (0=null, 1=int, 2=float, 3=text, 4=blob).
104
+ * * `value` - The value to bind.
105
+ */
106
+ bindAt(index: number, value: unknown): void
107
+ /**
108
+ * Step the statement and return result code:
109
+ * 1 = Row available, 2 = Done, 3 = I/O needed
110
+ */
111
+ step(): number
112
+ /** Get the current row data according to the presentation mode */
113
+ row(): unknown
114
+ /** Sets the presentation mode to raw. */
115
+ raw(raw?: boolean | undefined | null): void
116
+ /** Sets the presentation mode to pluck. */
117
+ pluck(pluck?: boolean | undefined | null): void
118
+ /**
119
+ * Sets safe integers mode for this statement.
120
+ *
121
+ * # Arguments
122
+ *
123
+ * * `toggle` - Whether to use safe integers.
124
+ */
125
+ safeIntegers(toggle?: boolean | undefined | null): void
126
+ /** Get column information for the statement */
127
+ columns(): unknown[]
128
+ /** Finalizes the statement. */
129
+ finalize(): void
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tursodatabase/database",
3
- "version": "0.1.4-pre.9",
3
+ "version": "0.1.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/tursodatabase/turso"
@@ -11,11 +11,12 @@
11
11
  "type": "module",
12
12
  "exports": {
13
13
  ".": "./dist/promise.js",
14
- "./sync": "./dist/sync.js"
14
+ "./compat": "./dist/compat.js"
15
15
  },
16
16
  "files": [
17
17
  "browser.js",
18
18
  "index.js",
19
+ "index.d.ts",
19
20
  "dist/**"
20
21
  ],
21
22
  "types": "index.d.ts",
@@ -60,9 +61,9 @@
60
61
  }
61
62
  },
62
63
  "optionalDependencies": {
63
- "@tursodatabase/database-linux-x64-gnu": "0.1.4-pre.9",
64
- "@tursodatabase/database-win32-x64-msvc": "0.1.4-pre.9",
65
- "@tursodatabase/database-darwin-universal": "0.1.4-pre.9",
66
- "@tursodatabase/database-wasm32-wasi": "0.1.4-pre.9"
64
+ "@tursodatabase/database-linux-x64-gnu": "0.1.4",
65
+ "@tursodatabase/database-win32-x64-msvc": "0.1.4",
66
+ "@tursodatabase/database-darwin-universal": "0.1.4",
67
+ "@tursodatabase/database-wasm32-wasi": "0.1.4"
67
68
  }
68
69
  }