cf-bun-mocks 0.2.0 → 0.2.1
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/package.json +1 -1
- package/src/d1.ts +5 -5
- package/src/workers.ts +2 -0
package/package.json
CHANGED
package/src/d1.ts
CHANGED
|
@@ -110,7 +110,7 @@ class D1DatabaseSessionMock implements D1DatabaseSession {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export class D1Mock implements D1Database {
|
|
113
|
-
|
|
113
|
+
db: Database;
|
|
114
114
|
|
|
115
115
|
constructor(
|
|
116
116
|
filename?: string,
|
|
@@ -124,11 +124,11 @@ export class D1Mock implements D1Database {
|
|
|
124
124
|
strict?: boolean;
|
|
125
125
|
}
|
|
126
126
|
) {
|
|
127
|
-
this
|
|
127
|
+
this.db = new Database(filename, options);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
prepare(query: string): D1PreparedStatement {
|
|
131
|
-
const stmt = this
|
|
131
|
+
const stmt = this.db.prepare(query);
|
|
132
132
|
return new D1PreparedStatementMock(stmt);
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -148,7 +148,7 @@ export class D1Mock implements D1Database {
|
|
|
148
148
|
async exec(query: string): Promise<D1ExecResult> {
|
|
149
149
|
const start = performance.now();
|
|
150
150
|
try {
|
|
151
|
-
const { changes: count } = this
|
|
151
|
+
const { changes: count } = this.db.run(query);
|
|
152
152
|
const duration = performance.now() - start;
|
|
153
153
|
return {
|
|
154
154
|
count,
|
|
@@ -170,7 +170,7 @@ export class D1Mock implements D1Database {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
async dump(): Promise<ArrayBuffer> {
|
|
173
|
-
const serialized = this
|
|
173
|
+
const serialized = this.db.serialize();
|
|
174
174
|
const buffer = serialized.buffer;
|
|
175
175
|
if (buffer instanceof SharedArrayBuffer) {
|
|
176
176
|
const newBuffer = new ArrayBuffer(buffer.byteLength);
|