@revojs/storage 0.2.18 → 0.2.20
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.d.ts +2 -0
- package/dist/index.js +9 -0
- package/dist/module/index.d.ts +2 -1
- package/dist/module/index.js +3 -2
- package/dist/providers/d1.d.ts +1 -0
- package/dist/providers/d1.js +3 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -225,6 +225,7 @@ export declare abstract class PreparedQuery {
|
|
|
225
225
|
}
|
|
226
226
|
export declare abstract class Session {
|
|
227
227
|
transaction<T>(run: (session: Session) => Awaitable<T>): Promise<T>;
|
|
228
|
+
batch(queries: Array<Query>): Promise<void>;
|
|
228
229
|
run(query: Query): unknown;
|
|
229
230
|
all(query: Query): unknown;
|
|
230
231
|
get(query: Query): unknown;
|
|
@@ -276,6 +277,7 @@ export declare abstract class Database<T extends Record<string, Table> = Record<
|
|
|
276
277
|
abstract update<TValue extends Table>(table: TValue): UpdateStatement<TValue>;
|
|
277
278
|
abstract delete<TValue extends Table>(table: TValue): DeleteStatement<TValue>;
|
|
278
279
|
abstract transaction<TResult>(run: (database: Database<T>) => Awaitable<TResult>): Promise<TResult>;
|
|
280
|
+
batch(statements: Array<InsertStatement | UpdateStatement | DeleteStatement>): Promise<void>;
|
|
279
281
|
}
|
|
280
282
|
export declare abstract class Table<TName extends string = string, TColumns extends Record<string, Column> = Record<string, Column>> {
|
|
281
283
|
readonly $name: TName;
|
package/dist/index.js
CHANGED
|
@@ -263,6 +263,11 @@ var Session = class {
|
|
|
263
263
|
async transaction(run) {
|
|
264
264
|
throw new Error("This storage provider does not support interactive transactions.");
|
|
265
265
|
}
|
|
266
|
+
async batch(queries) {
|
|
267
|
+
await this.transaction(async (session) => {
|
|
268
|
+
for (const query of queries) await session.run(query);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
266
271
|
run(query) {
|
|
267
272
|
return this.prepareQuery(query).run(query.parameters);
|
|
268
273
|
}
|
|
@@ -592,6 +597,9 @@ var Database = class {
|
|
|
592
597
|
tables: Object.values(this.$schema).map((table) => table.toMeta())
|
|
593
598
|
};
|
|
594
599
|
}
|
|
600
|
+
async batch(statements) {
|
|
601
|
+
if (statements.length > 0) await this.$session.batch(statements.map((statement) => statement.toQuery()));
|
|
602
|
+
}
|
|
595
603
|
};
|
|
596
604
|
var Table = class {
|
|
597
605
|
$name;
|
|
@@ -803,6 +811,7 @@ var UniqueIndex = class {
|
|
|
803
811
|
};
|
|
804
812
|
function toParameter(column, value) {
|
|
805
813
|
if (value instanceof Parameter || value instanceof Sql || value instanceof Table || value instanceof Column) return value;
|
|
814
|
+
if (value === null) return new Parameter(null);
|
|
806
815
|
return new Parameter(column.toDriverValue(value));
|
|
807
816
|
}
|
|
808
817
|
function combine(chunks, separator) {
|
package/dist/module/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
declare const _default: import("revojs/module").Module<"storage", {
|
|
2
2
|
storage: {
|
|
3
|
-
match: ("!**/*.d.ts" | "**/*.js" | "**/*.ts")[];
|
|
4
3
|
from: "./storage"[];
|
|
4
|
+
match: ("!**/*.d.ts" | "**/*.js" | "**/*.ts")[];
|
|
5
5
|
format: "object";
|
|
6
|
+
consumers: "server"[];
|
|
6
7
|
};
|
|
7
8
|
plugins: {
|
|
8
9
|
from: string[];
|
package/dist/module/index.js
CHANGED
|
@@ -6,13 +6,14 @@ var module_default = defineModule({
|
|
|
6
6
|
const { fromModule } = useModule(import.meta.url);
|
|
7
7
|
return { sources: {
|
|
8
8
|
storage: {
|
|
9
|
+
from: ["./storage"],
|
|
9
10
|
match: [
|
|
10
11
|
"**/*.js",
|
|
11
12
|
"**/*.ts",
|
|
12
13
|
"!**/*.d.ts"
|
|
13
14
|
],
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
format: "object",
|
|
16
|
+
consumers: ["server"]
|
|
16
17
|
},
|
|
17
18
|
plugins: { from: [fromModule("../plugins")] },
|
|
18
19
|
commands: { from: [fromModule("../commands")] }
|
package/dist/providers/d1.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class D1Session extends Session {
|
|
|
14
14
|
protected $client: D1Database | D1DatabaseSession;
|
|
15
15
|
constructor(client: D1Database | D1DatabaseSession);
|
|
16
16
|
transaction<T>(run: (session: Session) => Awaitable<T>): Promise<T>;
|
|
17
|
+
batch(queries: Array<Query>): Promise<void>;
|
|
17
18
|
prepareQuery(query: Query): D1PreparedQuery;
|
|
18
19
|
}
|
|
19
20
|
export declare function d1<T extends Record<string, SqliteTable>>(client: D1Database | D1DatabaseSession, schema: T): SqliteDatabase<T>;
|
package/dist/providers/d1.js
CHANGED
|
@@ -29,6 +29,9 @@ var D1Session = class extends Session {
|
|
|
29
29
|
async transaction(run) {
|
|
30
30
|
throw new Error("Cloudflare D1 does not support interactive transactions; use its atomic batch API instead.");
|
|
31
31
|
}
|
|
32
|
+
async batch(queries) {
|
|
33
|
+
await this.$client.batch(queries.map((query) => this.$client.prepare(query.sql).bind(...query.parameters)));
|
|
34
|
+
}
|
|
32
35
|
prepareQuery(query) {
|
|
33
36
|
return new D1PreparedQuery(query, this.$client.prepare(query.sql));
|
|
34
37
|
}
|