orez 0.5.24 → 0.5.26
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/README.md +2 -0
- package/dist/cf-do/application-sql.d.ts +17 -14
- package/dist/cf-do/application-sql.d.ts.map +1 -1
- package/dist/cf-do/application-sql.js +120 -24
- package/dist/cf-do/application-sql.js.map +1 -1
- package/dist/cf-do/cdc.d.ts +7 -0
- package/dist/cf-do/cdc.d.ts.map +1 -1
- package/dist/cf-do/cdc.js +1 -1
- package/dist/cf-do/cdc.js.map +1 -1
- package/dist/cf-do/tx-journal.d.ts +2 -0
- package/dist/cf-do/tx-journal.d.ts.map +1 -1
- package/dist/cf-do/tx-journal.js +17 -3
- package/dist/cf-do/tx-journal.js.map +1 -1
- package/dist/cf-do/worker.d.ts +42 -20
- package/dist/cf-do/worker.d.ts.map +1 -1
- package/dist/cf-do/worker.js +152 -78
- package/dist/cf-do/worker.js.map +1 -1
- package/package.json +3 -3
package/dist/cf-do/worker.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DurableObject } from 'cloudflare:workers';
|
|
1
|
+
import { DurableObject, RpcTarget } from 'cloudflare:workers';
|
|
2
2
|
import { type DeferredEffect } from 'orez-sync-cf-host/post-commit';
|
|
3
3
|
import { type CompiledTransactionQueryPlan, type TransactionQueryBudget, type TransactionQueryFormat } from 'orez-sync-cf-host/transaction-query';
|
|
4
4
|
import type { ApplicationSqlExecResult, ApplicationSqlTable } from './application-sql.js';
|
|
5
5
|
import type { SqlStatementMetadata } from 'orez-sync-cf-host';
|
|
6
6
|
export { createApplicationSqlClient } from './application-sql.js';
|
|
7
|
-
export type { ApplicationSqlClient, ApplicationSqlDurableObjectNamespace, ApplicationSqlExecResult, ApplicationSqlQueryCompiler, ApplicationSqlRpc, ApplicationSqlTable, ApplicationSqlTransaction, ApplicationSqlTransactionContext, ApplicationSqlTransactionWork, } from './application-sql.js';
|
|
7
|
+
export type { ApplicationSqlClient, ApplicationSqlClientOptions, ApplicationSqlDurableObjectNamespace, ApplicationSqlExecResult, ApplicationSqlQueryCompiler, ApplicationSqlRpc, ApplicationSqlSessionRpc, ApplicationSqlTable, ApplicationSqlTransaction, ApplicationSqlTransactionContext, ApplicationSqlTransactionWork, } from './application-sql.js';
|
|
8
8
|
export type { SqlStatementMetadata } from 'orez-sync-cf-host';
|
|
9
9
|
/**
|
|
10
10
|
* zero-do: Durable Object that exposes raw SQL execution over ctx.storage.sql.
|
|
@@ -36,6 +36,30 @@ export type ZeroDOTransactionExecutor = {
|
|
|
36
36
|
export type ZeroDOTransactionContext = {
|
|
37
37
|
defer(effect: DeferredEffect): void;
|
|
38
38
|
};
|
|
39
|
+
type ApplicationSqlSessionState = 'created' | 'active' | 'closed';
|
|
40
|
+
declare const APPLICATION_SQL_ACQUIRE: unique symbol;
|
|
41
|
+
declare const APPLICATION_SQL_QUERY: unique symbol;
|
|
42
|
+
declare const APPLICATION_SQL_EXEC: unique symbol;
|
|
43
|
+
declare const APPLICATION_SQL_QUERY_PLAN: unique symbol;
|
|
44
|
+
declare const APPLICATION_SQL_REGISTER_TABLES: unique symbol;
|
|
45
|
+
declare const APPLICATION_SQL_COMMIT: unique symbol;
|
|
46
|
+
declare const APPLICATION_SQL_ROLLBACK: unique symbol;
|
|
47
|
+
declare const APPLICATION_SQL_DISPOSE: unique symbol;
|
|
48
|
+
declare class ApplicationSqlSessionTarget extends RpcTarget {
|
|
49
|
+
readonly owner: ZeroDO;
|
|
50
|
+
readonly sessionID: string;
|
|
51
|
+
state: ApplicationSqlSessionState;
|
|
52
|
+
changed: boolean;
|
|
53
|
+
constructor(owner: ZeroDO, sessionID: string);
|
|
54
|
+
begin(): Promise<boolean>;
|
|
55
|
+
query<Row extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<Row[]>;
|
|
56
|
+
exec(sql: string, params?: readonly unknown[], metadata?: SqlStatementMetadata): Promise<ApplicationSqlExecResult>;
|
|
57
|
+
queryPlan<Result = unknown>(plan: CompiledTransactionQueryPlan, queryName?: string, queryBudget?: Partial<TransactionQueryBudget>): Promise<Result>;
|
|
58
|
+
registerTables(tables: readonly ApplicationSqlTable[]): Promise<void>;
|
|
59
|
+
commit(): Promise<void>;
|
|
60
|
+
rollback(): Promise<void>;
|
|
61
|
+
[Symbol.dispose](): void;
|
|
62
|
+
}
|
|
39
63
|
export declare class ZeroDO extends DurableObject {
|
|
40
64
|
private sql;
|
|
41
65
|
private watermarks;
|
|
@@ -47,8 +71,8 @@ export declare class ZeroDO extends DurableObject {
|
|
|
47
71
|
private writeBudgetAdminToken;
|
|
48
72
|
private activeWriteMeasurements;
|
|
49
73
|
private pendingChangesSchemaReady;
|
|
50
|
-
private
|
|
51
|
-
|
|
74
|
+
private activeApplicationSqlSession;
|
|
75
|
+
protected applicationSqlDidCommit(_changed: boolean): void;
|
|
52
76
|
private recordWriteBudgetRows;
|
|
53
77
|
private writeBudgetErrorResponse;
|
|
54
78
|
constructor(ctx: DurableObjectState, env: Env);
|
|
@@ -110,27 +134,25 @@ export declare class ZeroDO extends DurableObject {
|
|
|
110
134
|
*/
|
|
111
135
|
protected runApplicationTransaction<T>(compileQuery: ZeroDOQueryCompiler, work: (tx: ZeroDOTransactionExecutor, context: ZeroDOTransactionContext) => T | Promise<T>, queryBudget?: Partial<TransactionQueryBudget>): Promise<T>;
|
|
112
136
|
private assertApplicationSqlSession;
|
|
113
|
-
|
|
137
|
+
[APPLICATION_SQL_ACQUIRE](session: ApplicationSqlSessionTarget): boolean;
|
|
114
138
|
private releaseApplicationSqlTurn;
|
|
115
139
|
private withApplicationSqlTurn;
|
|
116
140
|
private registerApplicationSqlTables;
|
|
117
141
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* methods are intentionally absent from fetch().
|
|
142
|
+
* private durable object RPC surface for the application SQLite client. the
|
|
143
|
+
* disposable target exists before ownership acquisition, so waiting callers
|
|
144
|
+
* hold no server state and active cancellation rolls back the transaction.
|
|
145
|
+
* this method is intentionally absent from fetch().
|
|
123
146
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
applicationSqlRollback(sessionID: string): Promise<void>;
|
|
147
|
+
applicationSqlSession(sessionID: string): Promise<ApplicationSqlSessionTarget>;
|
|
148
|
+
private prepareApplicationSqlMutation;
|
|
149
|
+
[APPLICATION_SQL_QUERY]<Row extends Record<string, unknown> = Record<string, unknown>>(session: ApplicationSqlSessionTarget, sql: string, params?: readonly unknown[]): Promise<Row[]>;
|
|
150
|
+
[APPLICATION_SQL_EXEC](session: ApplicationSqlSessionTarget, sql: string, params?: readonly unknown[], metadata?: SqlStatementMetadata): Promise<ApplicationSqlExecResult>;
|
|
151
|
+
[APPLICATION_SQL_QUERY_PLAN]<Result = unknown>(session: ApplicationSqlSessionTarget, plan: CompiledTransactionQueryPlan, queryName?: string, queryBudget?: Partial<TransactionQueryBudget>): Promise<Result>;
|
|
152
|
+
[APPLICATION_SQL_REGISTER_TABLES](session: ApplicationSqlSessionTarget, tables: readonly ApplicationSqlTable[]): Promise<void>;
|
|
153
|
+
[APPLICATION_SQL_COMMIT](session: ApplicationSqlSessionTarget): Promise<void>;
|
|
154
|
+
[APPLICATION_SQL_ROLLBACK](session: ApplicationSqlSessionTarget): Promise<void>;
|
|
155
|
+
[APPLICATION_SQL_DISPOSE](session: ApplicationSqlSessionTarget): void;
|
|
134
156
|
private atomicallySync;
|
|
135
157
|
private invalidateSchemaCaches;
|
|
136
158
|
private tableHasColumn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/cf-do/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"worker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oBAAoB;IAW5B,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,YAAY;CAOrB;;mBAGsB,OAAO,OAAO,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;;AAD5D,wBAQC;AAqBD,UAAU,kBAAkB;IAC1B,OAAO,EAAE;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;KAAE,CAAA;IAC3E,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IACzD,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAAA;CACzC"}
|
package/dist/cf-do/worker.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @ts-nocheck — cloudflare:workers types not available in orez
|
|
2
|
-
import { DurableObject } from 'cloudflare:workers';
|
|
2
|
+
import { DurableObject, RpcTarget } from 'cloudflare:workers';
|
|
3
3
|
import { createPostCommitEffects, } from 'orez-sync-cf-host/post-commit';
|
|
4
4
|
import { executeTransactionQueryPlan, } from 'orez-sync-cf-host/transaction-query';
|
|
5
5
|
import { isSqlMutation, isSqlRowMutation, RollingRowWriteBudget, trackSqlCursorRowsWritten, trackedChangeRow, WriteBudgetExceededError, } from '../do-sql-tracking.js';
|
|
6
|
-
import { TransactionalCdc, } from './cdc.js';
|
|
6
|
+
import { TransactionalCdc, schemaChangeTargets, } from './cdc.js';
|
|
7
7
|
import { appendPendingChange, deletePendingChanges, ensurePendingChangesTable, rollbackPendingChanges, } from './row-undo.js';
|
|
8
|
-
import { commitTxJournal, recoverTxJournal, rollbackTxJournal, snapshotSideEffectWriteTables, snapshotTxSchema, upgradeToTableSnapshot, } from './tx-journal.js';
|
|
8
|
+
import { beginTxJournal, commitTxJournal, recoverTxJournal, rollbackTxJournal, snapshotSideEffectWriteTables, snapshotTxSchema, upgradeToTableSnapshot, } from './tx-journal.js';
|
|
9
9
|
import { DurableWatermarkState } from './watermark.js';
|
|
10
10
|
export { createApplicationSqlClient } from './application-sql.js';
|
|
11
11
|
const SCHEMA_VERSION = 1;
|
|
@@ -86,6 +86,49 @@ function applicationSqlTrack(metadata) {
|
|
|
86
86
|
operation: operations[metadata.kind],
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
+
const APPLICATION_SQL_ACQUIRE = Symbol('applicationSqlAcquire');
|
|
90
|
+
const APPLICATION_SQL_QUERY = Symbol('applicationSqlQuery');
|
|
91
|
+
const APPLICATION_SQL_EXEC = Symbol('applicationSqlExec');
|
|
92
|
+
const APPLICATION_SQL_QUERY_PLAN = Symbol('applicationSqlQueryPlan');
|
|
93
|
+
const APPLICATION_SQL_REGISTER_TABLES = Symbol('applicationSqlRegisterTables');
|
|
94
|
+
const APPLICATION_SQL_COMMIT = Symbol('applicationSqlCommit');
|
|
95
|
+
const APPLICATION_SQL_ROLLBACK = Symbol('applicationSqlRollback');
|
|
96
|
+
const APPLICATION_SQL_DISPOSE = Symbol('applicationSqlDispose');
|
|
97
|
+
class ApplicationSqlSessionTarget extends RpcTarget {
|
|
98
|
+
owner;
|
|
99
|
+
sessionID;
|
|
100
|
+
state = 'created';
|
|
101
|
+
changed = false;
|
|
102
|
+
constructor(owner, sessionID) {
|
|
103
|
+
super();
|
|
104
|
+
this.owner = owner;
|
|
105
|
+
this.sessionID = sessionID;
|
|
106
|
+
}
|
|
107
|
+
async begin() {
|
|
108
|
+
return this.owner[APPLICATION_SQL_ACQUIRE](this);
|
|
109
|
+
}
|
|
110
|
+
query(sql, params = []) {
|
|
111
|
+
return this.owner[APPLICATION_SQL_QUERY](this, sql, params);
|
|
112
|
+
}
|
|
113
|
+
exec(sql, params = [], metadata) {
|
|
114
|
+
return this.owner[APPLICATION_SQL_EXEC](this, sql, params, metadata);
|
|
115
|
+
}
|
|
116
|
+
queryPlan(plan, queryName, queryBudget) {
|
|
117
|
+
return this.owner[APPLICATION_SQL_QUERY_PLAN](this, plan, queryName, queryBudget);
|
|
118
|
+
}
|
|
119
|
+
registerTables(tables) {
|
|
120
|
+
return this.owner[APPLICATION_SQL_REGISTER_TABLES](this, tables);
|
|
121
|
+
}
|
|
122
|
+
commit() {
|
|
123
|
+
return this.owner[APPLICATION_SQL_COMMIT](this);
|
|
124
|
+
}
|
|
125
|
+
rollback() {
|
|
126
|
+
return this.owner[APPLICATION_SQL_ROLLBACK](this);
|
|
127
|
+
}
|
|
128
|
+
[Symbol.dispose]() {
|
|
129
|
+
this.owner[APPLICATION_SQL_DISPOSE](this);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
89
132
|
export class ZeroDO extends DurableObject {
|
|
90
133
|
sql;
|
|
91
134
|
watermarks;
|
|
@@ -97,8 +140,8 @@ export class ZeroDO extends DurableObject {
|
|
|
97
140
|
writeBudgetAdminToken;
|
|
98
141
|
activeWriteMeasurements = null;
|
|
99
142
|
pendingChangesSchemaReady = false;
|
|
100
|
-
|
|
101
|
-
|
|
143
|
+
activeApplicationSqlSession = null;
|
|
144
|
+
applicationSqlDidCommit(_changed) { }
|
|
102
145
|
recordWriteBudgetRows(rows) {
|
|
103
146
|
const wasTripped = this.writeBudget.status().tripped;
|
|
104
147
|
try {
|
|
@@ -228,7 +271,7 @@ export class ZeroDO extends DurableObject {
|
|
|
228
271
|
(request.method === 'GET' || request.method === 'POST'))
|
|
229
272
|
return this.handleChanges(request, url);
|
|
230
273
|
if (url.pathname === '/snapshot' && request.method === 'GET')
|
|
231
|
-
return this.withApplicationSqlTurn(() => this.handleSnapshot(url));
|
|
274
|
+
return this.withApplicationSqlTurn(() => this.handleSnapshot(url), request.signal);
|
|
232
275
|
if (url.pathname === '/notify' && request.method === 'POST')
|
|
233
276
|
return Response.json({ ok: true, cookie: this.cookie() });
|
|
234
277
|
return new Response('not found', { status: 404 });
|
|
@@ -868,38 +911,47 @@ export class ZeroDO extends DurableObject {
|
|
|
868
911
|
});
|
|
869
912
|
return value;
|
|
870
913
|
}
|
|
871
|
-
assertApplicationSqlSession(
|
|
872
|
-
if (
|
|
914
|
+
assertApplicationSqlSession(session) {
|
|
915
|
+
if (session.state !== 'active' || this.activeApplicationSqlSession !== session) {
|
|
873
916
|
throw new Error('application SQLite session is not active');
|
|
874
917
|
}
|
|
875
918
|
}
|
|
876
|
-
|
|
877
|
-
if (
|
|
878
|
-
|
|
879
|
-
if (this.applicationSqlSessionID === turnID)
|
|
880
|
-
return;
|
|
881
|
-
if (!this.applicationSqlSessionID) {
|
|
882
|
-
this.applicationSqlSessionID = turnID;
|
|
883
|
-
return;
|
|
919
|
+
[APPLICATION_SQL_ACQUIRE](session) {
|
|
920
|
+
if (session.state === 'active' && this.activeApplicationSqlSession === session) {
|
|
921
|
+
return true;
|
|
884
922
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
923
|
+
if (session.state !== 'created') {
|
|
924
|
+
throw new Error('application SQLite session cannot begin again');
|
|
925
|
+
}
|
|
926
|
+
if (this.activeApplicationSqlSession)
|
|
927
|
+
return false;
|
|
928
|
+
session.state = 'active';
|
|
929
|
+
this.activeApplicationSqlSession = session;
|
|
930
|
+
return true;
|
|
931
|
+
}
|
|
932
|
+
releaseApplicationSqlTurn(session) {
|
|
933
|
+
this.assertApplicationSqlSession(session);
|
|
934
|
+
session.state = 'closed';
|
|
935
|
+
this.activeApplicationSqlSession = null;
|
|
936
|
+
}
|
|
937
|
+
async withApplicationSqlTurn(work, signal) {
|
|
938
|
+
const session = await this.applicationSqlSession(crypto.randomUUID());
|
|
939
|
+
const dispose = () => session[Symbol.dispose]();
|
|
940
|
+
signal?.addEventListener('abort', dispose, { once: true });
|
|
898
941
|
try {
|
|
942
|
+
while (!(await session.begin())) {
|
|
943
|
+
if (signal?.aborted)
|
|
944
|
+
throw new Error('application SQLite request was canceled');
|
|
945
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
946
|
+
}
|
|
899
947
|
return await work();
|
|
900
948
|
}
|
|
901
949
|
finally {
|
|
902
|
-
|
|
950
|
+
signal?.removeEventListener('abort', dispose);
|
|
951
|
+
if (session.state === 'active')
|
|
952
|
+
this.releaseApplicationSqlTurn(session);
|
|
953
|
+
else if (session.state !== 'closed')
|
|
954
|
+
dispose();
|
|
903
955
|
}
|
|
904
956
|
}
|
|
905
957
|
registerApplicationSqlTables(tables) {
|
|
@@ -912,80 +964,102 @@ export class ZeroDO extends DurableObject {
|
|
|
912
964
|
}
|
|
913
965
|
}
|
|
914
966
|
/**
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
*
|
|
918
|
-
*
|
|
919
|
-
* methods are intentionally absent from fetch().
|
|
967
|
+
* private durable object RPC surface for the application SQLite client. the
|
|
968
|
+
* disposable target exists before ownership acquisition, so waiting callers
|
|
969
|
+
* hold no server state and active cancellation rolls back the transaction.
|
|
970
|
+
* this method is intentionally absent from fetch().
|
|
920
971
|
*/
|
|
921
|
-
async
|
|
922
|
-
return this.withApplicationSqlTurn(() => this.runApplicationTransaction(() => {
|
|
923
|
-
throw new Error('queryAst requires an application SQLite transaction compiler');
|
|
924
|
-
}, (tx) => tx.query(sql, params)));
|
|
925
|
-
}
|
|
926
|
-
async applicationSqlExec(sql, params = [], metadata) {
|
|
927
|
-
return this.withApplicationSqlTurn(() => this.runApplicationTransaction(() => {
|
|
928
|
-
throw new Error('queryAst requires an application SQLite transaction compiler');
|
|
929
|
-
}, (tx) => tx.exec(sql, params, metadata)));
|
|
930
|
-
}
|
|
931
|
-
async applicationSqlRegisterTables(tables) {
|
|
932
|
-
await this.withApplicationSqlTurn(() => this.atomically(() => this.registerApplicationSqlTables(tables)));
|
|
933
|
-
}
|
|
934
|
-
async applicationSqlBegin(sessionID) {
|
|
972
|
+
async applicationSqlSession(sessionID) {
|
|
935
973
|
if (!sessionID)
|
|
936
974
|
throw new TypeError('application SQLite session id is required');
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
975
|
+
return new ApplicationSqlSessionTarget(this, sessionID);
|
|
976
|
+
}
|
|
977
|
+
prepareApplicationSqlMutation(sessionID, sql) {
|
|
978
|
+
if (!isSqlMutation(sql))
|
|
979
|
+
return;
|
|
980
|
+
if (!isSqlRowMutation(sql)) {
|
|
981
|
+
const targets = schemaChangeTargets(sql);
|
|
982
|
+
if (/^\s*CREATE\s+TABLE\s+IF\s+NOT\s+EXISTS\b/i.test(sql) &&
|
|
983
|
+
targets.length > 0 &&
|
|
984
|
+
targets.every((table) => this.tableExists(table))) {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
beginTxJournal(this.sql, sessionID, 'application');
|
|
988
|
+
snapshotTxSchema(this.sql, sessionID, 'application', targets);
|
|
989
|
+
return;
|
|
944
990
|
}
|
|
991
|
+
beginTxJournal(this.sql, sessionID, 'application');
|
|
945
992
|
}
|
|
946
|
-
async
|
|
947
|
-
this.assertApplicationSqlSession(
|
|
948
|
-
return this.atomically(() =>
|
|
993
|
+
async [APPLICATION_SQL_QUERY](session, sql, params = []) {
|
|
994
|
+
this.assertApplicationSqlSession(session);
|
|
995
|
+
return this.atomically(() => {
|
|
996
|
+
this.prepareApplicationSqlMutation(session.sessionID, sql);
|
|
997
|
+
return this.executeSQL(sql, [...params], undefined, session.sessionID).rows;
|
|
998
|
+
});
|
|
949
999
|
}
|
|
950
|
-
async
|
|
951
|
-
this.assertApplicationSqlSession(
|
|
1000
|
+
async [APPLICATION_SQL_EXEC](session, sql, params = [], metadata) {
|
|
1001
|
+
this.assertApplicationSqlSession(session);
|
|
952
1002
|
return this.atomically(() => {
|
|
953
|
-
|
|
1003
|
+
this.prepareApplicationSqlMutation(session.sessionID, sql);
|
|
1004
|
+
const result = this.executeSQL(sql, [...params], applicationSqlTrack(metadata), session.sessionID);
|
|
1005
|
+
if (result.changes > 0)
|
|
1006
|
+
session.changed = true;
|
|
954
1007
|
return { changes: result.changes };
|
|
955
1008
|
});
|
|
956
1009
|
}
|
|
957
|
-
async
|
|
958
|
-
this.assertApplicationSqlSession(
|
|
959
|
-
return this.atomically(() => executeTransactionQueryPlan(plan, (sql, params) => this.executeSQL(sql, params, undefined, sessionID).rows, { queryName, budget: queryBudget }));
|
|
1010
|
+
async [APPLICATION_SQL_QUERY_PLAN](session, plan, queryName, queryBudget) {
|
|
1011
|
+
this.assertApplicationSqlSession(session);
|
|
1012
|
+
return this.atomically(() => executeTransactionQueryPlan(plan, (sql, params) => this.executeSQL(sql, params, undefined, session.sessionID).rows, { queryName, budget: queryBudget }));
|
|
960
1013
|
}
|
|
961
|
-
async
|
|
962
|
-
this.assertApplicationSqlSession(
|
|
1014
|
+
async [APPLICATION_SQL_REGISTER_TABLES](session, tables) {
|
|
1015
|
+
this.assertApplicationSqlSession(session);
|
|
963
1016
|
await this.atomically(() => this.registerApplicationSqlTables(tables));
|
|
964
1017
|
}
|
|
965
|
-
async
|
|
966
|
-
this.assertApplicationSqlSession(
|
|
1018
|
+
async [APPLICATION_SQL_COMMIT](session) {
|
|
1019
|
+
this.assertApplicationSqlSession(session);
|
|
967
1020
|
try {
|
|
968
1021
|
await this.atomically(() => {
|
|
969
|
-
this.commitPendingTrackedChanges(sessionID);
|
|
970
|
-
commitTxJournal(this.sql, sessionID);
|
|
1022
|
+
this.commitPendingTrackedChanges(session.sessionID);
|
|
1023
|
+
commitTxJournal(this.sql, session.sessionID);
|
|
971
1024
|
});
|
|
972
1025
|
}
|
|
973
1026
|
finally {
|
|
974
|
-
this.releaseApplicationSqlTurn(
|
|
1027
|
+
this.releaseApplicationSqlTurn(session);
|
|
975
1028
|
}
|
|
1029
|
+
this.applicationSqlDidCommit(session.changed);
|
|
976
1030
|
}
|
|
977
|
-
async
|
|
978
|
-
this.assertApplicationSqlSession(
|
|
1031
|
+
async [APPLICATION_SQL_ROLLBACK](session) {
|
|
1032
|
+
this.assertApplicationSqlSession(session);
|
|
979
1033
|
try {
|
|
980
1034
|
await this.atomically(() => {
|
|
981
|
-
this.rollbackPendingTrackedChanges(sessionID);
|
|
982
|
-
rollbackTxJournal(this.sql, sessionID);
|
|
983
|
-
this.deletePendingTrackedChanges(sessionID);
|
|
1035
|
+
this.rollbackPendingTrackedChanges(session.sessionID);
|
|
1036
|
+
rollbackTxJournal(this.sql, session.sessionID);
|
|
1037
|
+
this.deletePendingTrackedChanges(session.sessionID);
|
|
1038
|
+
});
|
|
1039
|
+
this.invalidateSchemaCaches();
|
|
1040
|
+
}
|
|
1041
|
+
finally {
|
|
1042
|
+
this.releaseApplicationSqlTurn(session);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
[APPLICATION_SQL_DISPOSE](session) {
|
|
1046
|
+
if (session.state === 'closed')
|
|
1047
|
+
return;
|
|
1048
|
+
if (session.state === 'created') {
|
|
1049
|
+
session.state = 'closed';
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
this.assertApplicationSqlSession(session);
|
|
1053
|
+
try {
|
|
1054
|
+
this.atomicallySync(() => {
|
|
1055
|
+
this.rollbackPendingTrackedChanges(session.sessionID);
|
|
1056
|
+
rollbackTxJournal(this.sql, session.sessionID);
|
|
1057
|
+
this.deletePendingTrackedChanges(session.sessionID);
|
|
984
1058
|
});
|
|
985
1059
|
this.invalidateSchemaCaches();
|
|
986
1060
|
}
|
|
987
1061
|
finally {
|
|
988
|
-
this.releaseApplicationSqlTurn(
|
|
1062
|
+
this.releaseApplicationSqlTurn(session);
|
|
989
1063
|
}
|
|
990
1064
|
}
|
|
991
1065
|
atomicallySync(work) {
|