react-native-nitro-sqlite 9.8.1 → 10.0.0

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 (145) hide show
  1. package/RNNitroSQLite.podspec +7 -3
  2. package/android/CMakeLists.txt +3 -2
  3. package/android/build.gradle +2 -0
  4. package/android/sqlite-flags.gradle +47 -0
  5. package/cpp/NitroSQLiteDatabaseConnections.cpp +306 -0
  6. package/cpp/NitroSQLiteDatabaseConnections.hpp +86 -0
  7. package/cpp/{databaseMigration.cpp → NitroSQLiteDatabaseMigration.cpp} +2 -2
  8. package/cpp/{sqliteExecuteBatch.cpp → NitroSQLiteExecuteBatch.cpp} +4 -4
  9. package/cpp/{sqliteExecuteBatch.hpp → NitroSQLiteExecuteBatch.hpp} +3 -6
  10. package/cpp/{importSqlFile.cpp → NitroSQLiteImportSqlFile.cpp} +4 -4
  11. package/cpp/{importSqlFile.hpp → NitroSQLiteImportSqlFile.hpp} +3 -3
  12. package/cpp/{macros.hpp → NitroSQLiteMacros.hpp} +3 -3
  13. package/cpp/NitroSQLiteOperations.cpp +396 -0
  14. package/cpp/NitroSQLiteOperations.hpp +72 -0
  15. package/cpp/{types.hpp → NitroSQLiteTypes.hpp} +3 -6
  16. package/cpp/{utils.hpp → NitroSQLiteUtils.hpp} +2 -2
  17. package/cpp/hybridObjects/HybridNitroSQLite.cpp +108 -22
  18. package/cpp/hybridObjects/HybridNitroSQLite.hpp +49 -5
  19. package/cpp/hybridObjects/HybridNitroSQLitePreparedStatement.cpp +59 -0
  20. package/cpp/hybridObjects/HybridNitroSQLitePreparedStatement.hpp +33 -0
  21. package/cpp/hybridObjects/HybridNitroSQLiteQueryResult.hpp +6 -4
  22. package/ios/OnLoad.mm +38 -2
  23. package/lib/commonjs/DatabaseQueue.js +52 -16
  24. package/lib/commonjs/DatabaseQueue.js.map +1 -1
  25. package/lib/commonjs/NitroSQLiteError.js +6 -7
  26. package/lib/commonjs/NitroSQLiteError.js.map +1 -1
  27. package/lib/commonjs/OnLoad.js +1 -1
  28. package/lib/commonjs/index.js +8 -3
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/operations/execute.js +19 -4
  31. package/lib/commonjs/operations/execute.js.map +1 -1
  32. package/lib/commonjs/operations/executeBatch.js +19 -6
  33. package/lib/commonjs/operations/executeBatch.js.map +1 -1
  34. package/lib/commonjs/operations/prepare.js +54 -0
  35. package/lib/commonjs/operations/prepare.js.map +1 -0
  36. package/lib/commonjs/operations/session.js +106 -30
  37. package/lib/commonjs/operations/session.js.map +1 -1
  38. package/lib/commonjs/operations/transaction.js +30 -5
  39. package/lib/commonjs/operations/transaction.js.map +1 -1
  40. package/lib/commonjs/specs/NitroSQLitePreparedStatement.nitro.js +6 -0
  41. package/lib/commonjs/specs/NitroSQLitePreparedStatement.nitro.js.map +1 -0
  42. package/lib/commonjs/typeORM.js +10 -3
  43. package/lib/commonjs/typeORM.js.map +1 -1
  44. package/lib/commonjs/types.js +35 -9
  45. package/lib/commonjs/types.js.map +1 -1
  46. package/lib/module/DatabaseQueue.js +52 -16
  47. package/lib/module/DatabaseQueue.js.map +1 -1
  48. package/lib/module/NitroSQLiteError.js +6 -7
  49. package/lib/module/NitroSQLiteError.js.map +1 -1
  50. package/lib/module/OnLoad.js +1 -1
  51. package/lib/module/index.js +8 -3
  52. package/lib/module/index.js.map +1 -1
  53. package/lib/module/operations/execute.js +20 -5
  54. package/lib/module/operations/execute.js.map +1 -1
  55. package/lib/module/operations/executeBatch.js +20 -7
  56. package/lib/module/operations/executeBatch.js.map +1 -1
  57. package/lib/module/operations/prepare.js +49 -0
  58. package/lib/module/operations/prepare.js.map +1 -0
  59. package/lib/module/operations/session.js +107 -31
  60. package/lib/module/operations/session.js.map +1 -1
  61. package/lib/module/operations/transaction.js +30 -5
  62. package/lib/module/operations/transaction.js.map +1 -1
  63. package/lib/module/specs/NitroSQLitePreparedStatement.nitro.js +4 -0
  64. package/lib/module/specs/NitroSQLitePreparedStatement.nitro.js.map +1 -0
  65. package/lib/module/typeORM.js +11 -3
  66. package/lib/module/typeORM.js.map +1 -1
  67. package/lib/module/types.js +48 -9
  68. package/lib/module/types.js.map +1 -1
  69. package/lib/typescript/commonjs/DatabaseQueue.d.ts +15 -7
  70. package/lib/typescript/commonjs/DatabaseQueue.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/NitroSQLiteError.d.ts +6 -7
  72. package/lib/typescript/commonjs/NitroSQLiteError.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/index.d.ts +9 -2
  74. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/operations/execute.d.ts +17 -2
  76. package/lib/typescript/commonjs/operations/execute.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/operations/executeBatch.d.ts +15 -2
  78. package/lib/typescript/commonjs/operations/executeBatch.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/operations/prepare.d.ts +13 -0
  80. package/lib/typescript/commonjs/operations/prepare.d.ts.map +1 -0
  81. package/lib/typescript/commonjs/operations/session.d.ts +8 -0
  82. package/lib/typescript/commonjs/operations/session.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/operations/transaction.d.ts +11 -1
  84. package/lib/typescript/commonjs/operations/transaction.d.ts.map +1 -1
  85. package/lib/typescript/commonjs/specs/NitroSQLite.nitro.d.ts +83 -2
  86. package/lib/typescript/commonjs/specs/NitroSQLite.nitro.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/specs/NitroSQLitePreparedStatement.nitro.d.ts +26 -0
  88. package/lib/typescript/commonjs/specs/NitroSQLitePreparedStatement.nitro.d.ts.map +1 -0
  89. package/lib/typescript/commonjs/specs/NitroSQLiteQueryResult.nitro.d.ts +9 -15
  90. package/lib/typescript/commonjs/specs/NitroSQLiteQueryResult.nitro.d.ts.map +1 -1
  91. package/lib/typescript/commonjs/typeORM.d.ts +14 -3
  92. package/lib/typescript/commonjs/typeORM.d.ts.map +1 -1
  93. package/lib/typescript/commonjs/types.d.ts +124 -21
  94. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  95. package/lib/typescript/module/DatabaseQueue.d.ts +15 -7
  96. package/lib/typescript/module/DatabaseQueue.d.ts.map +1 -1
  97. package/lib/typescript/module/NitroSQLiteError.d.ts +6 -7
  98. package/lib/typescript/module/NitroSQLiteError.d.ts.map +1 -1
  99. package/lib/typescript/module/index.d.ts +9 -2
  100. package/lib/typescript/module/index.d.ts.map +1 -1
  101. package/lib/typescript/module/operations/execute.d.ts +17 -2
  102. package/lib/typescript/module/operations/execute.d.ts.map +1 -1
  103. package/lib/typescript/module/operations/executeBatch.d.ts +15 -2
  104. package/lib/typescript/module/operations/executeBatch.d.ts.map +1 -1
  105. package/lib/typescript/module/operations/prepare.d.ts +13 -0
  106. package/lib/typescript/module/operations/prepare.d.ts.map +1 -0
  107. package/lib/typescript/module/operations/session.d.ts +8 -0
  108. package/lib/typescript/module/operations/session.d.ts.map +1 -1
  109. package/lib/typescript/module/operations/transaction.d.ts +11 -1
  110. package/lib/typescript/module/operations/transaction.d.ts.map +1 -1
  111. package/lib/typescript/module/specs/NitroSQLite.nitro.d.ts +83 -2
  112. package/lib/typescript/module/specs/NitroSQLite.nitro.d.ts.map +1 -1
  113. package/lib/typescript/module/specs/NitroSQLitePreparedStatement.nitro.d.ts +26 -0
  114. package/lib/typescript/module/specs/NitroSQLitePreparedStatement.nitro.d.ts.map +1 -0
  115. package/lib/typescript/module/specs/NitroSQLiteQueryResult.nitro.d.ts +9 -15
  116. package/lib/typescript/module/specs/NitroSQLiteQueryResult.nitro.d.ts.map +1 -1
  117. package/lib/typescript/module/typeORM.d.ts +14 -3
  118. package/lib/typescript/module/typeORM.d.ts.map +1 -1
  119. package/lib/typescript/module/types.d.ts +124 -21
  120. package/lib/typescript/module/types.d.ts.map +1 -1
  121. package/nitrogen/generated/android/RNNitroSQLite+autolinking.cmake +1 -0
  122. package/nitrogen/generated/shared/c++/HybridNitroSQLitePreparedStatementSpec.cpp +24 -0
  123. package/nitrogen/generated/shared/c++/HybridNitroSQLitePreparedStatementSpec.hpp +73 -0
  124. package/nitrogen/generated/shared/c++/HybridNitroSQLiteSpec.cpp +3 -0
  125. package/nitrogen/generated/shared/c++/HybridNitroSQLiteSpec.hpp +8 -2
  126. package/package.json +4 -2
  127. package/src/DatabaseQueue.ts +81 -25
  128. package/src/NitroSQLiteError.ts +6 -7
  129. package/src/OnLoad.ts +1 -1
  130. package/src/index.ts +7 -3
  131. package/src/operations/execute.ts +22 -3
  132. package/src/operations/executeBatch.ts +20 -5
  133. package/src/operations/prepare.ts +69 -0
  134. package/src/operations/session.ts +136 -45
  135. package/src/operations/transaction.ts +37 -4
  136. package/src/specs/NitroSQLite.nitro.ts +84 -2
  137. package/src/specs/NitroSQLitePreparedStatement.nitro.ts +28 -0
  138. package/src/specs/NitroSQLiteQueryResult.nitro.ts +9 -15
  139. package/src/typeORM.ts +14 -3
  140. package/src/types.ts +135 -21
  141. package/cpp/operations.cpp +0 -358
  142. package/cpp/operations.hpp +0 -56
  143. /package/android/{cpp-adapter.cpp → RNNitroSQLiteAdapter.cpp} +0 -0
  144. /package/cpp/{databaseMigration.hpp → NitroSQLiteDatabaseMigration.hpp} +0 -0
  145. /package/cpp/{logs.hpp → NitroSQLiteLogs.hpp} +0 -0
@@ -4,59 +4,135 @@ import { HybridNitroSQLite } from "../nitro.js";
4
4
  import { transaction } from "./transaction.js";
5
5
  import { executeAsyncManaged, executeManaged } from "./execute.js";
6
6
  import { executeBatch, executeBatchAsync } from "./executeBatch.js";
7
+ import { prepare } from "./prepare.js";
7
8
  import NitroSQLiteError from "../NitroSQLiteError.js";
8
- import { closeDatabaseQueue, isDatabaseOpen, openDatabaseQueue, queueOperationAsync, startOperationSync } from "../DatabaseQueue.js";
9
+ import { closeDatabaseQueue, getDatabaseQueue, isDatabaseOpen, openDatabaseQueue, queueStatementAsync, startOperationSync } from "../DatabaseQueue.js";
10
+ /**
11
+ * Open a database and return a managed connection. The default connection is
12
+ * addressed by its name, and opening it twice throws. Set `connection` to
13
+ * `'independent'` to open another native handle to the same file. Async calls
14
+ * on each connection run in call order.
15
+ * @param options Database name, optional directory, connection mode, and read-only setting.
16
+ * @returns A connection bound to the opened native handle.
17
+ */
9
18
  export function open(options) {
10
- openDatabaseQueue(options.name);
11
- try {
12
- HybridNitroSQLite.open(options.name, options.location);
13
- } catch (error) {
14
- closeDatabaseQueue(options.name);
15
- throw NitroSQLiteError.fromError(error);
16
- }
19
+ const {
20
+ name,
21
+ location: databaseLocation,
22
+ connection,
23
+ readOnly
24
+ } = options;
25
+ const {
26
+ connectionId,
27
+ queueKey
28
+ } = openNativeConnection(options);
29
+ const connectionQueue = getDatabaseQueue(queueKey);
30
+ const assertCurrentConnection = () => {
31
+ if (!isDatabaseOpen(queueKey) || getDatabaseQueue(queueKey) !== connectionQueue) {
32
+ throw new NitroSQLiteError(`Database ${name} is not open. There is no connection to the database.`);
33
+ }
34
+ };
35
+ const assertNoReplacement = () => {
36
+ if (isDatabaseOpen(queueKey) && getDatabaseQueue(queueKey) !== connectionQueue) {
37
+ throw new NitroSQLiteError(`Database ${name} has been reopened with another connection.`);
38
+ }
39
+ };
40
+ const runSyncOperation = callback => {
41
+ try {
42
+ assertCurrentConnection();
43
+ return startOperationSync(queueKey, callback);
44
+ } catch (error) {
45
+ throw NitroSQLiteError.fromError(error);
46
+ }
47
+ };
48
+ const runOperation = callback => {
49
+ assertCurrentConnection();
50
+ return callback();
51
+ };
17
52
  return {
18
53
  close: () => {
19
- try {
20
- startOperationSync(options.name, () => HybridNitroSQLite.close(options.name));
21
- closeDatabaseQueue(options.name);
22
- } catch (error) {
23
- throw NitroSQLiteError.fromError(error);
24
- }
54
+ runSyncOperation(() => HybridNitroSQLite.close(connectionId));
55
+ closeDatabaseQueue(queueKey);
25
56
  },
26
57
  delete: () => {
58
+ if (readOnly) {
59
+ throw new NitroSQLiteError(`Cannot delete read-only database ${name}.`);
60
+ }
61
+ let dropFailed = false;
27
62
  try {
28
- if (!isDatabaseOpen(options.name)) {
29
- HybridNitroSQLite.drop(options.name, options.location);
63
+ assertNoReplacement();
64
+ const drop = () => {
65
+ try {
66
+ if (connection === 'independent') {
67
+ HybridNitroSQLite.drop(name, databaseLocation, connectionId);
68
+ } else {
69
+ HybridNitroSQLite.drop(name, databaseLocation);
70
+ }
71
+ } catch (error) {
72
+ dropFailed = true;
73
+ throw error;
74
+ }
75
+ };
76
+ if (!isDatabaseOpen(queueKey)) {
77
+ drop();
30
78
  return;
31
79
  }
32
- startOperationSync(options.name, () => HybridNitroSQLite.drop(options.name, options.location));
33
- closeDatabaseQueue(options.name);
80
+ startOperationSync(queueKey, drop);
81
+ closeDatabaseQueue(queueKey);
34
82
  } catch (error) {
83
+ if (dropFailed && isDatabaseOpen(queueKey) && getDatabaseQueue(queueKey) === connectionQueue && !HybridNitroSQLite.isConnectionOpen(connectionId)) {
84
+ closeDatabaseQueue(queueKey);
85
+ }
35
86
  throw NitroSQLiteError.fromError(error);
36
87
  }
37
88
  },
38
- attach: (dbNameToAttach, alias, location) => runSyncOperation(options.name, () => HybridNitroSQLite.attach(options.name, dbNameToAttach, alias, location)),
39
- detach: alias => runSyncOperation(options.name, () => HybridNitroSQLite.detach(options.name, alias)),
40
- transaction: fn => transaction(options.name, fn),
41
- execute: (query, params) => executeManaged(options.name, query, params),
42
- executeAsync: (query, params) => executeAsyncManaged(options.name, query, params),
43
- executeBatch: commands => executeBatch(options.name, commands),
44
- executeBatchAsync: commands => executeBatchAsync(options.name, commands),
45
- loadFile: location => runSyncOperation(options.name, () => HybridNitroSQLite.loadFile(options.name, location)),
46
- loadFileAsync: location => queueOperationAsync(options.name, async () => {
89
+ attach: (dbNameToAttach, alias, location) => runSyncOperation(() => HybridNitroSQLite.attach(connectionId, dbNameToAttach, alias, location)),
90
+ detach: alias => runSyncOperation(() => HybridNitroSQLite.detach(connectionId, alias)),
91
+ transaction: async fn => runOperation(() => transaction(connectionId, fn, false, queueKey)),
92
+ execute: (query, params) => runOperation(() => executeManaged(connectionId, query, params, queueKey)),
93
+ executeAsync: async (query, params) => runOperation(() => executeAsyncManaged(connectionId, query, params, queueKey)),
94
+ prepare: query => runOperation(() => prepare(connectionId, query, queueKey)),
95
+ executeBatch: commands => runOperation(() => executeBatch(connectionId, commands, queueKey)),
96
+ executeBatchAsync: async commands => runOperation(() => executeBatchAsync(connectionId, commands, queueKey)),
97
+ loadFile: location => runSyncOperation(() => HybridNitroSQLite.loadFile(connectionId, location)),
98
+ loadFileAsync: location => runOperation(() => queueStatementAsync(queueKey, async () => {
47
99
  try {
48
- return await HybridNitroSQLite.loadFileAsync(options.name, location);
100
+ return await HybridNitroSQLite.loadFileAsync(connectionId, location);
49
101
  } catch (error) {
50
102
  throw NitroSQLiteError.fromError(error);
51
103
  }
52
- })
104
+ }))
53
105
  };
54
106
  }
55
- function runSyncOperation(dbName, callback) {
107
+ function openNativeConnection(options) {
108
+ if (options.connection === 'independent') {
109
+ let connectionId;
110
+ try {
111
+ connectionId = options.readOnly ? HybridNitroSQLite.openConnection(options.name, options.location, true) : HybridNitroSQLite.openConnection(options.name, options.location);
112
+ const queueKey = Symbol(options.name);
113
+ openDatabaseQueue(queueKey);
114
+ return {
115
+ connectionId,
116
+ queueKey
117
+ };
118
+ } catch (error) {
119
+ throw NitroSQLiteError.fromError(error);
120
+ }
121
+ }
122
+ openDatabaseQueue(options.name);
56
123
  try {
57
- return startOperationSync(dbName, callback);
124
+ if (options.readOnly) {
125
+ HybridNitroSQLite.open(options.name, options.location, true);
126
+ } else {
127
+ HybridNitroSQLite.open(options.name, options.location);
128
+ }
58
129
  } catch (error) {
130
+ closeDatabaseQueue(options.name);
59
131
  throw NitroSQLiteError.fromError(error);
60
132
  }
133
+ return {
134
+ connectionId: options.name,
135
+ queueKey: options.name
136
+ };
61
137
  }
62
138
  //# sourceMappingURL=session.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["HybridNitroSQLite","transaction","executeAsyncManaged","executeManaged","executeBatch","executeBatchAsync","NitroSQLiteError","closeDatabaseQueue","isDatabaseOpen","openDatabaseQueue","queueOperationAsync","startOperationSync","open","options","name","location","error","fromError","close","delete","drop","attach","dbNameToAttach","alias","runSyncOperation","detach","fn","execute","query","params","executeAsync","commands","loadFile","loadFileAsync","dbName","callback"],"sourceRoot":"../../../src","sources":["operations/session.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,aAAU;AAC5C,SAASC,WAAW,QAAQ,kBAAe;AAU3C,SAASC,mBAAmB,EAAEC,cAAc,QAAQ,cAAW;AAC/D,SAASC,YAAY,EAAEC,iBAAiB,QAAQ,mBAAgB;AAChE,OAAOC,gBAAgB,MAAM,wBAAqB;AAClD,SACEC,kBAAkB,EAClBC,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,EACnBC,kBAAkB,QACb,qBAAkB;AAEzB,OAAO,SAASC,IAAIA,CAClBC,OAAqC,EACd;EACvBJ,iBAAiB,CAACI,OAAO,CAACC,IAAI,CAAC;EAE/B,IAAI;IACFd,iBAAiB,CAACY,IAAI,CAACC,OAAO,CAACC,IAAI,EAAED,OAAO,CAACE,QAAQ,CAAC;EACxD,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdT,kBAAkB,CAACM,OAAO,CAACC,IAAI,CAAC;IAChC,MAAMR,gBAAgB,CAACW,SAAS,CAACD,KAAK,CAAC;EACzC;EAEA,OAAO;IACLE,KAAK,EAAEA,CAAA,KAAM;MACX,IAAI;QACFP,kBAAkB,CAACE,OAAO,CAACC,IAAI,EAAE,MAC/Bd,iBAAiB,CAACkB,KAAK,CAACL,OAAO,CAACC,IAAI,CACtC,CAAC;QACDP,kBAAkB,CAACM,OAAO,CAACC,IAAI,CAAC;MAClC,CAAC,CAAC,OAAOE,KAAK,EAAE;QACd,MAAMV,gBAAgB,CAACW,SAAS,CAACD,KAAK,CAAC;MACzC;IACF,CAAC;IACDG,MAAM,EAAEA,CAAA,KAAM;MACZ,IAAI;QACF,IAAI,CAACX,cAAc,CAACK,OAA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B,iBAAiB,CAACQ,OAAO,CAACC,IAAI,EAAEiB,QAAQ,CAAC;IAC3CC,QAAQ,EAAGjB,QAAgB,IACzBS,gBAAgB,CAACX,OAAO,CAACC,IAAI,EAAE,MAC7Bd,iBAAiB,CAACgC,QAAQ,CAACnB,OAAO,CAACC,IAAI,EAAEC,QAAQ,CACnD,CAAC;IACHkB,aAAa,EAAGlB,QAAgB,IAC9BL,mBAAmB,CAACG,OAAO,CAACC,IAAI,EAAE,YAAY;MAC5C,IAAI;QACF,OAAO,MAAMd,iBAAiB,CAACiC,aAAa,CAACpB,OAAO,CAACC,IAAI,EAAEC,QAAQ,CAAC;MACtE,CAAC,CAAC,OAAOC,KAAK,EAAE;QACd,MAAMV,gBAAgB,CAACW,SAAS,CAACD,KAAK,CAAC;MACzC;IACF,CAAC;EACL,CAAC;AACH;AAEA,SAASQ,gBAAgBA,CAASU,MAAc,EAAEC,QAAsB,EAAE;EACxE,IAAI;IACF,OAAOxB,kBAAkB,CAACuB,MAAM,EAAEC,QAAQ,CAAC;EAC7C,CAAC,CAAC,OAAOnB,KAAK,EAAE;IACd,MAAMV,gBAAgB,CAACW,SAAS,CAACD,KAAK,CAAC;EACzC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["HybridNitroSQLite","transaction","executeAsyncManaged","executeManaged","executeBatch","executeBatchAsync","prepare","NitroSQLiteError","closeDatabaseQueue","getDatabaseQueue","isDatabaseOpen","openDatabaseQueue","queueStatementAsync","startOperationSync","open","options","name","location","databaseLocation","connection","readOnly","connectionId","queueKey","openNativeConnection","connectionQueue","assertCurrentConnection","assertNoReplacement","runSyncOperation","callback","error","fromError","runOperation","close","delete","dropFailed","drop","isConnectionOpen","attach","dbNameToAttach","alias","detach","fn","execute","query","params","executeAsync","commands","loadFile","loadFileAsync","openConnection","Symbol"],"sourceRoot":"../../../src","sources":["operations/session.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,aAAU;AAC5C,SAASC,WAAW,QAAQ,kBAAe;AA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iBAAiB,CAACc,IAAI,CAACC,OAAO,CAACC,IAAI,EAAED,OAAO,CAACE,QAAQ,CAAC;IACxD;EACF,CAAC,CAAC,OAAOY,KAAK,EAAE;IACdrB,kBAAkB,CAACO,OAAO,CAACC,IAAI,CAAC;IAChC,MAAMT,gBAAgB,CAACuB,SAAS,CAACD,KAAK,CAAC;EACzC;EACA,OAAO;IAAER,YAAY,EAAEN,OAAO,CAACC,IAAI;IAAEM,QAAQ,EAAEP,OAAO,CAACC;EAAK,CAAC;AAC/D","ignoreList":[]}
@@ -3,25 +3,45 @@
3
3
  import { queueOperationAsync, throwIfDatabaseIsNotOpen } from "../DatabaseQueue.js";
4
4
  import { executeAsyncNative, executeNative } from "./execute.js";
5
5
  import NitroSQLiteError from "../NitroSQLiteError.js";
6
- export const transaction = async (dbName, transactionCallback, isExclusive = false) => {
7
- throwIfDatabaseIsNotOpen(dbName);
6
+ /** Queue a transaction for an open managed connection.
7
+ * Use only the supplied `tx` for work on this database inside the callback.
8
+ * A successful callback commits unless it explicitly committed or rolled back;
9
+ * a thrown error rolls back unless the transaction was already finalized.
10
+ * @param dbName Name of the open database.
11
+ * @param transactionCallback Async callback receiving the transaction handle.
12
+ * @param isExclusive Begin an exclusive transaction when true.
13
+ * @returns The callback's result after the transaction finishes.
14
+ */
15
+ export const transaction = async (dbName, transactionCallback, isExclusive = false, queueKey = dbName) => {
16
+ throwIfDatabaseIsNotOpen(queueKey);
8
17
  let isFinished = false;
18
+ const pendingAsyncStatements = new Set();
19
+ const throwIfAsyncPending = () => {
20
+ if (pendingAsyncStatements.size > 0) {
21
+ throw new NitroSQLiteError(`Cannot run synchronous operation on transaction ${dbName} while async queries are pending. Await all tx.executeAsync calls first.`);
22
+ }
23
+ };
9
24
  const executeOnTransaction = (query, params) => {
10
25
  if (isFinished) {
11
26
  throw new NitroSQLiteError(`Cannot execute query on finalized transaction: ${dbName}`);
12
27
  }
28
+ throwIfAsyncPending();
13
29
  return executeNative(dbName, query, params);
14
30
  };
15
31
  const executeAsyncOnTransaction = (query, params) => {
16
32
  if (isFinished) {
17
33
  throw new NitroSQLiteError(`Cannot execute query on finalized transaction: ${dbName}`);
18
34
  }
19
- return executeAsyncNative(dbName, query, params);
35
+ const pending = executeAsyncNative(dbName, query, params);
36
+ pendingAsyncStatements.add(pending);
37
+ pending.then(() => pendingAsyncStatements.delete(pending), () => pendingAsyncStatements.delete(pending));
38
+ return pending;
20
39
  };
21
40
  const commit = () => {
22
41
  if (isFinished) {
23
42
  throw new NitroSQLiteError(`Cannot execute commit on finalized transaction: ${dbName}`);
24
43
  }
44
+ throwIfAsyncPending();
25
45
  isFinished = true;
26
46
  return executeNative(dbName, 'COMMIT');
27
47
  };
@@ -29,10 +49,11 @@ export const transaction = async (dbName, transactionCallback, isExclusive = fal
29
49
  if (isFinished) {
30
50
  throw new NitroSQLiteError(`Cannot execute rollback on finalized transaction: ${dbName}`);
31
51
  }
52
+ throwIfAsyncPending();
32
53
  isFinished = true;
33
54
  return executeNative(dbName, 'ROLLBACK');
34
55
  };
35
- return await queueOperationAsync(dbName, async () => {
56
+ return await queueOperationAsync(queueKey, async () => {
36
57
  try {
37
58
  await executeAsyncNative(dbName, isExclusive ? 'BEGIN EXCLUSIVE TRANSACTION' : 'BEGIN TRANSACTION');
38
59
  const result = await transactionCallback({
@@ -45,8 +66,12 @@ export const transaction = async (dbName, transactionCallback, isExclusive = fal
45
66
  return result;
46
67
  } catch (executionError) {
47
68
  if (!isFinished) {
69
+ isFinished = true;
70
+ // All queued native calls must finish before ROLLBACK can run
71
+ // synchronously on this connection.
72
+ await Promise.allSettled(pendingAsyncStatements);
48
73
  try {
49
- rollback();
74
+ executeNative(dbName, 'ROLLBACK');
50
75
  } catch (rollbackError) {
51
76
  throw NitroSQLiteError.fromError(rollbackError);
52
77
  }
@@ -1 +1 @@
1
- {"version":3,"names":["queueOperationAsync","throwIfDatabaseIsNotOpen","executeAsyncNative","executeNative","NitroSQLiteError","transaction","dbName","transactionCallback","isExclusive","isFinished","executeOnTransaction","query","params","executeAsyncOnTransaction","commit","rollback","result","execute","executeAsync","executionError","rollbackError","fromError"],"sourceRoot":"../../../src","sources":["operations/transaction.ts"],"mappings":";;AAAA,SAASA,mBAAmB,EAAEC,wBAAwB,QAAQ,qBAAkB;AAOhF,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAW;AAC7D,OAAOC,gBAAgB,MAAM,wBAAqB;AAElD,OAAO,MAAMC,WAAW,GAAG,MAAAA,CACzBC,MAAc,EACdC,mBAAyD,EACzDC,WAAW,GAAG,KAAK,KAChB;EACHP,wBAAwB,CAACK,MAAM,CAAC;EAEhC,IAAIG,UAAU,GAAG,KAAK;EAEtB,MAAMC,oBAAoB,GAAGA,CAC3BC,KAAa,EACbC,MAA0B,KACL;IACrB,IAAIH,UAAU,EAAE;MACd,MAAM,IAAIL,gBAAgB,CACxB,kDAAkDE,MAAM,EAC1D,CAAC;IACH;IACA,OAAOH,aAAa,CAACG,MAAM,EAAEK,KAAK,EAAEC,MAAM,CAAC;EAC7C,CAAC;EAED,MAAMC,yBAAyB,GAAGA,CAChCF,KAAa,EACbC,MAA0B,KACI;IAC9B,IAAIH,UAAU,EAAE;MACd,MAAM,IAAIL,gBAAgB,CACxB,kDAAkDE,MAAM,EAC1D,CAAC;IACH;IACA,OAAOJ,kBAAkB,CAACI,MAAM,EAAEK,KAAK,EAAEC,MAAM,CAAC;EAClD,CAAC;EAED,MAAME,MAAM,GAAGA,CAAA,KAAM;IACnB,IAAIL,UAAU,EAAE;MACd,MAAM,IAAIL,gBAAgB,CACxB,mDAAmDE,MAAM,EAC3D,CAAC;IACH;IACAG,UAAU,GAAG,IAAI;IACjB,OAAON,aAAa,CAACG,MAAM,EAAE,QAAQ,CAAC;EACxC,CAAC;EAED,MAAMS,QAAQ,GAAGA,CAAA,KAAM;IACrB,IAAIN,UAAU,EAAE;MACd,MAAM,IAAIL,gBAAgB,CACxB,qDAAqDE,MAAM,EAC7D,CAAC;IACH;IACAG,UAAU,GAAG,IAAI;IACjB,OAAON,aAAa,CAACG,MAAM,EAAE,UAAU,CAAC;EAC1C,CAAC;EAED,OAAO,MAAMN,mBAAmB,CAACM,MAAM,EAAE,YAAY;IACnD,IAAI;MACF,MAAMJ,kBAAkB,CACtBI,MAAM,EACNE,WAAW,GAAG,6BAA6B,GAAG,mBAChD,CAAC;MAED,MAAMQ,MAAM,GAAG,MAAMT,mBAAmB,CAAC;QACvCO,MAAM;QACNG,OAAO,EAAEP,oBAAoB;QAC7BQ,YAAY,EAAEL,yBAAyB;QACvCE;MACF,CAAC,CAAC;MAEF,IAAI,CAACN,UAAU,EAAEK,MAAM,CAAC,CAAC;MAEzB,OAAOE,MAAM;IACf,CAAC,CAAC,OAAOG,cAAc,EAAE;MACvB,IAAI,CAACV,UAAU,EAAE;QACf,IAAI;UACFM,QAAQ,CAAC,CAAC;QACZ,CAAC,CAAC,OAAOK,aAAa,EAAE;UACtB,MAAMhB,gBAAgB,CAACiB,SAAS,CAACD,aAAa,CAAC;QACjD;MACF;MAEA,MAAMhB,gBAAgB,CAACiB,SAAS,CAACF,cAAc,CAAC;IAClD;EACF,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["queueOperationAsync","throwIfDatabaseIsNotOpen","executeAsyncNative","executeNative","NitroSQLiteError","transaction","dbName","transactionCallback","isExclusive","queueKey","isFinished","pendingAsyncStatements","Set","throwIfAsyncPending","size","executeOnTransaction","query","params","executeAsyncOnTransaction","pending","add","then","delete","commit","rollback","result","execute","executeAsync","executionError","Promise","allSettled","rollbackError","fromError"],"sourceRoot":"../../../src","sources":["operations/transaction.ts"],"mappings":";;AAAA,SAASA,mBAAmB,EAAEC,wBAAwB,QAAQ,qBAAkB;AAOhF,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAW;AAC7D,OAAOC,gBAAgB,MAAM,wBAAqB;AAGlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAA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{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/NitroSQLitePreparedStatement.nitro.ts"],"mappings":"","ignoreList":[]}
@@ -8,11 +8,19 @@
8
8
  // |_| |_| |_| |______\____/|_| \_\_| |_| /_/ \_\_| |_____|
9
9
 
10
10
  import * as Operations from "./operations/session.js";
11
- /**
12
- * DO NOT USE THIS! THIS IS MEANT FOR TYPEORM
13
- * If you are looking for a convenience wrapper use `connect`
11
+
12
+ /** Callback-oriented connection returned to TypeORM. */
13
+
14
+ /** Adapter for TypeORM's React Native driver. Application code should use `open()`.
15
+ * `openDatabase` reports success or failure through callbacks and returns the
16
+ * connection on success, or `null` when opening fails.
14
17
  */
15
18
  export const typeORMDriver = {
19
+ /** Open a database for TypeORM.
20
+ * @param options Database name and optional relative directory.
21
+ * @param ok Receives the adapter connection on success.
22
+ * @param fail Receives the opening error on failure.
23
+ */
16
24
  openDatabase: (options, ok, fail) => {
17
25
  try {
18
26
  const db = Operations.open(options);
@@ -1 +1 @@
1
- {"version":3,"names":["Operations","typeORMDriver","openDatabase","options","ok","fail","db","open","connection","executeSql","sql","params","okExecute","failExecute","result","executeAsync","e","transaction","fn","close","okClose","failClose","attach","dbNameToAttach","alias","location","callback","detach"],"sourceRoot":"../../src","sources":["typeORM.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAO,KAAKA,UAAU,MAAM,yBAAsB;AAoBlD;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAG;EAC3BC,YAAY,EAAEA,CACZC,OAGC,EACDC,EAA8C,EAC9CC,IAA2B,KACa;IACxC,IAAI;MACF,MAAMC,EAAE,GAAGN,UAAU,CAACO,IAAI,CAACJ,OAAO,CAAC;MAEnC,MAAMK,UAAwC,GAAG;QAC/CC,UAAU,EAAE,MAAAA,CACVC,GAAW,EACXC,MAAqC,EACrCC,SAA8C,EAC9CC,WAAkC,KAC/B;UACH,IAAI;YACF,MAAMC,MAAM,GAAG,MAAMR,EAAE,CAACS,YAAY,CAAUL,GAAG,EAAEC,MAAM,CAAC;YAC1DC,SAAS,CAACE,MAAM,CAAC;UACnB,CAAC,CAAC,OAAOE,CAAU,EAAE;YACnBH,WAAW,CAACG,CAAW,CAAC;UAC1B;QACF,CAAC;QACDC,WAAW,EACTC,EAAsC,IACpB;UAClB,OAAOZ,EAAE,CAACW,WAAW,CAACC,EAAE,CAAC;QAC3B,CAAC;QACDC,KAAK,EAAEA,CAACC,OAAmB,EAAEC,SAA+B,KAAK;UAC/D,IAAI;YACFf,EAAE,CAACa,KAAK,CAAC,CAAC;YACVC,OAAO,CAAC,CAAC;UACX,CAAC,CAAC,OAAOJ,CAAC,EAAE;YACVK,SAAS,CAACL,CAAC,CAAC;UACd;QACF,CAAC;QACDM,MAAM,EAAEA,CACNC,cAAsB,EACtBC,KAAa,EACbC,QAA4B,EAC5BC,QAAoB,KACjB;UACHpB,EAAE,CAACgB,MAAM,CAACC,cAAc,EAAEC,KAAK,EAAEC,QAAQ,CAAC;UAC1CC,QAAQ,CAAC,CAAC;QACZ,CAAC;QACDC,MAAM,EAAEA,CAACH,KAAa,EAAEE,QAAoB,KAAK;UAC/CpB,EAAE,CAACqB,MAAM,CAACH,KAAK,CAAC;UAChBE,QAAQ,CAAC,CAAC;QACZ;MACF,CAAC;MAEDtB,EAAE,CAACI,UAAU,CAAC;MAEd,OAAOA,UAAU;IACnB,CAAC,CAAC,OAAOQ,CAAU,EAAE;MACnBX,IAAI,CAACW,CAAW,CAAC;MAEjB,OAAO,IAAI;IACb;EACF;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Operations","typeORMDriver","openDatabase","options","ok","fail","db","open","connection","executeSql","sql","params","okExecute","failExecute","result","executeAsync","e","transaction","fn","close","okClose","failClose","attach","dbNameToAttach","alias","location","callback","detach"],"sourceRoot":"../../src","sources":["typeORM.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAO,KAAKA,UAAU,MAAM,yBAAsB;;AAElD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A,UAAU;IACnB,CAAC,CAAC,OAAOQ,CAAU,EAAE;MACnBX,IAAI,CAACW,CAAW,CAAC;MAEjB,OAAO,IAAI;IACb;EACF;AACF,CAAC","ignoreList":[]}
@@ -1,30 +1,69 @@
1
1
  "use strict";
2
2
 
3
+ /** Options for `open()` and `NitroSQLite.open()`. */
4
+
5
+ /** A managed connection bound to one database name. Do not use it after closing or deleting it. */
6
+
7
+ /** SQLite value categories reported in query column metadata. */
3
8
  export let ColumnType = /*#__PURE__*/function (ColumnType) {
9
+ /** Boolean declaration. */
4
10
  ColumnType[ColumnType["BOOLEAN"] = 0] = "BOOLEAN";
11
+ /** Floating point declaration. */
5
12
  ColumnType[ColumnType["NUMBER"] = 1] = "NUMBER";
13
+ /** Integer declaration. */
6
14
  ColumnType[ColumnType["INT64"] = 2] = "INT64";
15
+ /** Text declaration. */
7
16
  ColumnType[ColumnType["TEXT"] = 3] = "TEXT";
17
+ /** Blob declaration. */
8
18
  ColumnType[ColumnType["ARRAY_BUFFER"] = 4] = "ARRAY_BUFFER";
19
+ /** Missing or unrecognized declaration. */
9
20
  ColumnType[ColumnType["NULL_VALUE"] = 5] = "NULL_VALUE";
10
21
  return ColumnType;
11
22
  }({});
12
23
 
24
+ /** Values accepted by bound SQL parameters and returned in result rows. */
25
+
26
+ /** Positional values for SQL placeholders. */
27
+
28
+ /** A row keyed by result column names. */
29
+
30
+ /** Query result with a row adapter for TypeORM-style consumers. */
31
+
32
+ /** Indexable view of query rows. */
33
+
34
+ /** Execute one SQL statement synchronously and return its typed rows.
35
+ * @param query SQL statement with optional positional placeholders.
36
+ * @param params Values bound to the placeholders.
37
+ */
38
+
39
+ /** Queue one SQL statement and resolve with its typed rows.
40
+ * @param query SQL statement with optional positional placeholders.
41
+ * @param params Values bound to the placeholders.
42
+ */
43
+
13
44
  /**
14
- * Allows the execution of bulk of sql commands
15
- * inside a transaction
16
- * If a single query must be executed many times with different arguments, its preferred
17
- * to declare it a single time, and use an array of array parameters.
45
+ * A reusable SQL statement bound to the connection that prepared it. Each
46
+ * execution resets the statement and its bindings before applying new values.
47
+ * Finalize it before closing the connection.
18
48
  */
19
49
 
20
50
  /**
21
- * status: 0 or undefined for correct execution, 1 for error
22
- * message: if status === 1, here you will find error description
23
- * rowsAffected: Number of affected rows if status == 0
51
+ * Execute a prepared statement with optional positional values and return typed rows.
52
+ * Each call replaces the previous parameter bindings.
53
+ * @param params Values bound to the statement's positional placeholders.
24
54
  */
25
55
 
26
56
  /**
27
- * Result of loading a file and executing every line as a SQL command
28
- * Similar to BatchQueryResult
57
+ * Queue a prepared statement execution and resolve with typed rows. Calls on the
58
+ * same managed connection run in queue order.
59
+ * @param params Values bound to the statement's positional placeholders.
29
60
  */
61
+
62
+ /** Handle valid only while its transaction callback is active. */
63
+
64
+ /** One command in a batch. A nested `params` array repeats the query for each parameter set. */
65
+
66
+ /** Result of a committed SQL batch. Errors are thrown rather than returned here. */
67
+
68
+ /** Result of importing a SQL file in one transaction. */
30
69
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ColumnType"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;AAuBA,WAAYA,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;;AAsDtB;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":["ColumnType"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;AAEA;;AAqBA;;AA4DA;AACA,WAAYA,UAAU,0BAAVA,UAAU;EACpB;EADUA,UAAU,CAAVA,UAAU;EAGpB;EAHUA,UAAU,CAAVA,UAAU;EAKpB;EALUA,UAAU,CAAVA,UAAU;EAOpB;EAPUA,UAAU,CAAVA,UAAU;EASpB;EATUA,UAAU,CAAVA,UAAU;EAWpB;EAXUA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;;AAetB;;AAGA;;AAGA;;AAGA;;AAOA;;AAgBA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;;AAOA;;AAYA;;AAQA;;AAMA","ignoreList":[]}
@@ -1,4 +1,5 @@
1
1
  export interface QueuedOperation {
2
+ kind: 'statement' | 'exclusive';
2
3
  /**
3
4
  * Starts the operation
4
5
  */
@@ -7,12 +8,19 @@ export interface QueuedOperation {
7
8
  export type DatabaseQueue = {
8
9
  queue: QueuedOperation[];
9
10
  inProgress: boolean;
11
+ activeStatements: number;
12
+ draining: boolean;
10
13
  };
11
- export declare function openDatabaseQueue(dbName: string): void;
12
- export declare function closeDatabaseQueue(dbName: string): void;
13
- export declare function isDatabaseOpen(dbName: string): boolean;
14
- export declare function throwIfDatabaseIsNotOpen(dbName: string): void;
15
- export declare function getDatabaseQueue(dbName: string): DatabaseQueue;
16
- export declare function queueOperationAsync<Result>(dbName: string, callback: () => Promise<Result>): Promise<Result>;
17
- export declare function startOperationSync<Result>(dbName: string, callback: () => Result): Result;
14
+ /** Identity of a managed connection's operation queue. Application code should
15
+ * omit the optional queue key on package helpers; connections choose it for you.
16
+ */
17
+ export type DatabaseQueueKey = string | symbol;
18
+ export declare function openDatabaseQueue(dbName: DatabaseQueueKey): void;
19
+ export declare function closeDatabaseQueue(dbName: DatabaseQueueKey): void;
20
+ export declare function isDatabaseOpen(dbName: DatabaseQueueKey): boolean;
21
+ export declare function throwIfDatabaseIsNotOpen(dbName: DatabaseQueueKey): void;
22
+ export declare function getDatabaseQueue(dbName: DatabaseQueueKey): DatabaseQueue;
23
+ export declare function queueOperationAsync<Result>(dbName: DatabaseQueueKey, callback: () => Promise<Result>): Promise<Result>;
24
+ export declare function queueStatementAsync<Result>(dbName: DatabaseQueueKey, callback: () => Promise<Result>): Promise<Result>;
25
+ export declare function startOperationSync<Result>(dbName: DatabaseQueueKey, callback: () => Result): Result;
18
26
  //# sourceMappingURL=DatabaseQueue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseQueue.d.ts","sourceRoot":"","sources":["../../../src/DatabaseQueue.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,QAQ/C;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,QAUhD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,WAE5C;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,QAKtD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,iBAK9C;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,mBAwBhC;AAgBD,wBAAgB,kBAAkB,CAAC,MAAM,EACvC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,MAAM,GACrB,MAAM,CAiBR"}
1
+ {"version":3,"file":"DatabaseQueue.d.ts","sourceRoot":"","sources":["../../../src/DatabaseQueue.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,GAAG,WAAW,CAAA;IAC/B;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,UAAU,EAAE,OAAO,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAA;AAI9C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,QAazD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QAU1D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,WAEtD;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,QAKhE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,iBAKxD;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAC9B,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAC9B,OAAO,CAAC,MAAM,CAAC,CAEjB;AAwED,wBAAgB,kBAAkB,CAAC,MAAM,EACvC,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,MAAM,MAAM,GACrB,MAAM,CAkBR"}
@@ -1,12 +1,11 @@
1
- /**
2
- * Custom error class for NitroSQLite operations
3
- * Extends the native Error class with proper prototype chain and error handling
4
- */
1
+ /** Error thrown by managed NitroSQLite operations. Native errors are wrapped with this class. */
5
2
  export default class NitroSQLiteError extends Error {
3
+ /** Create an error with a message and optional cause. */
6
4
  constructor(message: string, options?: ErrorOptions);
7
- /**
8
- * Converts an unknown error to a NitroSQLiteError
9
- * Preserves stack traces and error causes when available
5
+ /** Convert an unknown thrown value to `NitroSQLiteError`.
6
+ * Existing instances pass through; `Error` values keep their stack and cause.
7
+ * @param error Value to normalize.
8
+ * @returns A NitroSQLiteError instance.
10
9
  */
11
10
  static fromError(error: unknown): NitroSQLiteError;
12
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NitroSQLiteError.d.ts","sourceRoot":"","sources":["../../../src/NitroSQLiteError.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAQnD;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB;CAyBnD"}
1
+ {"version":3,"file":"NitroSQLiteError.d.ts","sourceRoot":"","sources":["../../../src/NitroSQLiteError.ts"],"names":[],"mappings":"AAEA,iGAAiG;AACjG,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,KAAK;IACjD,yDAAyD;gBAC7C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAQnD;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB;CAyBnD"}
@@ -1,16 +1,23 @@
1
1
  import { open } from './operations/session';
2
2
  import { execute, executeAsync } from './operations/execute';
3
+ import { prepare } from './operations/prepare';
3
4
  import { executeBatch, executeBatchAsync } from './operations/executeBatch';
5
+ /** Database entry point. Prefer {@link open} for a managed connection.
6
+ * `native` exposes the Nitro object directly and bypasses the JavaScript queue.
7
+ */
4
8
  export declare const NitroSQLite: {
5
9
  native: import("./specs/NitroSQLite.nitro").NitroSQLite;
6
10
  open: typeof open;
7
- transaction: <Result = void>(dbName: string, transactionCallback: (tx: import("./types").Transaction) => Promise<Result>, isExclusive?: boolean) => Promise<Result>;
11
+ transaction: <Result = void>(dbName: string, transactionCallback: (tx: import("./types").Transaction) => Promise<Result>, isExclusive?: boolean, queueKey?: import("./DatabaseQueue").DatabaseQueueKey) => Promise<Result>;
8
12
  execute: typeof execute;
9
13
  executeAsync: typeof executeAsync;
14
+ prepare: typeof prepare;
10
15
  executeBatch: typeof executeBatch;
11
16
  executeBatchAsync: typeof executeBatchAsync;
17
+ openConnection(dbName: string, location?: string, readOnly?: boolean): string;
18
+ isConnectionOpen(connectionId: string): boolean;
12
19
  close(dbName: string): void;
13
- drop(dbName: string, location?: string): void;
20
+ drop(dbName: string, location?: string, connectionId?: string): void;
14
21
  attach(mainDbName: string, dbNameToAttach: string, alias: string, location?: string): void;
15
22
  detach(mainDbName: string, alias: string): void;
16
23
  loadFile(dbName: string, location: string): import("./types").FileLoadResult;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAE5D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAI3E,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;CAYvB,CAAA;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAChE,mBAAmB,SAAS,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAI3E;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;CAYvB,CAAA;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAChE,mBAAmB,SAAS,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA"}
@@ -1,10 +1,25 @@
1
1
  import type { QueryResult, QueryResultRow, SQLiteQueryParams } from '../types';
2
2
  import type { NitroSQLiteQueryResult } from '../specs/NitroSQLiteQueryResult.nitro';
3
+ import type { DatabaseQueueKey } from '../DatabaseQueue';
4
+ /** Execute one SQL statement synchronously by database name.
5
+ * Uses the managed queue when the database has an open managed connection.
6
+ * @param dbName Name of an open native database.
7
+ * @param query SQL statement with optional positional placeholders.
8
+ * @param params Values bound to the placeholders.
9
+ * @returns The query result with typed rows.
10
+ */
3
11
  export declare function execute<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams): QueryResult<Row>;
4
- export declare function executeManaged<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams): QueryResult<Row>;
12
+ export declare function executeManaged<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams, queueKey?: DatabaseQueueKey): QueryResult<Row>;
5
13
  export declare function executeNative<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams): QueryResult<Row>;
14
+ /** Execute one SQL statement asynchronously by database name.
15
+ * Uses the managed queue when the database has an open managed connection.
16
+ * @param dbName Name of an open native database.
17
+ * @param query SQL statement with optional positional placeholders.
18
+ * @param params Values bound to the placeholders.
19
+ * @returns A promise of the query result with typed rows.
20
+ */
6
21
  export declare function executeAsync<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams): Promise<QueryResult<Row>>;
7
- export declare function executeAsyncManaged<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams): Promise<QueryResult<Row>>;
22
+ export declare function executeAsyncManaged<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams, queueKey?: DatabaseQueueKey): Promise<QueryResult<Row>>;
8
23
  export declare function executeAsyncNative<Row extends QueryResultRow = never>(dbName: string, query: string, params?: SQLiteQueryParams): Promise<QueryResult<Row>>;
9
24
  export declare function buildJSQueryResult<Row extends QueryResultRow = never>(result: NitroSQLiteQueryResult): QueryResult<Row>;
10
25
  //# sourceMappingURL=execute.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../../src/operations/execute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE9E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAOnF,wBAAgB,OAAO,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EACxD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,WAAW,CAAC,GAAG,CAAC,CAMlB;AAED,wBAAgB,cAAc,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EAC/D,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,WAAW,CAAC,GAAG,CAAC,CAElB;AAED,wBAAgB,aAAa,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EAC9D,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,WAAW,CAAC,GAAG,CAAC,CAOlB;AAED,wBAAsB,YAAY,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EACnE,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAM3B;AAED,wBAAsB,mBAAmB,CAAC,GAAG,SAAS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MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,WAAW,CAAC,GAAG,CAAC,CAOlB;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EACnE,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAM3B;AAED,wBAAsB,mBAAmB,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EAC1E,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,EAC1B,QAAQ,GAAE,gBAAyB,GAClC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAI3B;AAED,wBAAsB,kBAAkB,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EACzE,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAW3B;AAED,wBAAgB,kBAAkB,CAAC,GAAG,SAAS,cAAc,GAAG,KAAK,EACnE,MAAM,EAAE,sBAAsB,GAC7B,WAAW,CAAC,GAAG,CAAC,CAWlB"}
@@ -1,4 +1,17 @@
1
1
  import type { BatchQueryCommand, BatchQueryResult } from '../types';
2
- export declare function executeBatch(dbName: string, commands: BatchQueryCommand[]): BatchQueryResult;
3
- export declare function executeBatchAsync(dbName: string, commands: BatchQueryCommand[]): Promise<BatchQueryResult>;
2
+ import type { DatabaseQueueKey } from '../DatabaseQueue';
3
+ /** Execute a batch synchronously in one exclusive transaction.
4
+ * Requires an open managed connection; throws if it is busy or the batch is empty.
5
+ * @param dbName Name of the open database.
6
+ * @param commands SQL commands and optional parameter sets.
7
+ * @returns Total affected row count.
8
+ */
9
+ export declare function executeBatch(dbName: string, commands: BatchQueryCommand[], queueKey?: DatabaseQueueKey): BatchQueryResult;
10
+ /** Queue a batch in one exclusive transaction.
11
+ * Requires an open managed connection; a failed command rolls back the batch.
12
+ * @param dbName Name of the open database.
13
+ * @param commands SQL commands and optional parameter sets.
14
+ * @returns A promise of the total affected row count.
15
+ */
16
+ export declare function executeBatchAsync(dbName: string, commands: BatchQueryCommand[], queueKey?: DatabaseQueueKey): Promise<BatchQueryResult>;
4
17
  //# sourceMappingURL=executeBatch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"executeBatch.d.ts","sourceRoot":"","sources":["../../../../src/operations/executeBatch.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEnE,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,iBAAiB,EAAE,GAC5B,gBAAgB,CAUlB;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,iBAAiB,EAAE,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAU3B"}
1
+ {"version":3,"file":"executeBatch.d.ts","sourceRoot":"","sources":["../../../../src/operations/executeBatch.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,QAAQ,GAAE,gBAAyB,GAClC,gBAAgB,CAUlB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,QAAQ,GAAE,gBAAyB,GAClC,OAAO,CAAC,gBAAgB,CAAC,CAU3B"}
@@ -0,0 +1,13 @@
1
+ import type { PreparedStatement } from '../types';
2
+ import type { DatabaseQueueKey } from '../DatabaseQueue';
3
+ /**
4
+ * Prepare one SQL statement on an open managed connection for repeated execution.
5
+ * Synchronous preparation throws if the connection is busy. Finalize the returned
6
+ * statement before closing the connection.
7
+ * @param dbName Database name or independent connection ID.
8
+ * @param query SQL statement with optional positional placeholders.
9
+ * @param queueKey Internal managed queue key; omit when using the public API.
10
+ * @returns A statement whose executions use the same connection queue.
11
+ */
12
+ export declare function prepare(dbName: string, query: string, queueKey?: DatabaseQueueKey): PreparedStatement;
13
+ //# sourceMappingURL=prepare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../../../../src/operations/prepare.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EAIlB,MAAM,UAAU,CAAA;AAGjB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,gBAAyB,GAClC,iBAAiB,CA2CnB"}