deno.land / x / pg_mem@2.8.1 / transaction.ts

transaction.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { _Transaction } from './interfaces-private.ts';import { Map as ImMap, Set as ImSet } from 'https://deno.land/x/immutable@4.0.0-rc.12-deno.1/mod.ts';import { NotSupported, QueryError } from './interfaces.ts';
export class Transaction implements _Transaction { private origData: ImMap<symbol, any>; private transientData: any = {};
static root() { return new Transaction(null, ImMap()); }
get isChild() { return !!this.parent; }
private constructor(private parent: Transaction | null, private data: ImMap<symbol, any>) { this.origData = data; }

clone() { return new Transaction(null, this.data); }
fork(): _Transaction { return new Transaction(this, this.data); }
commit(): _Transaction { if (!this.parent) { return this; } if (this.parent.data !== this.origData) { throw new NotSupported('Concurrent transactions'); } this.parent.data = this.data; return this.parent; }
delete(identity: symbol): void { this.data = this.data.delete(identity); }
set<T>(identity: symbol, data: T): T { this.data = this.data.set(identity, data); return data; }
get<T>(identity: symbol): T { return this.data.get(identity); }
getMap<T extends ImMap<any, any>>(identity: symbol): T { let got = this.data.get(identity); if (!got) { this.data = this.data.set(identity, got = ImMap()); } return got as any as T; }
getSet<T>(identity: symbol): ImSet<T> { let got = this.data.get(identity); if (!got) { this.data = this.data.set(identity, got = ImSet()); } return got as any; }
fullCommit() { const ret = this.commit(); return ret.isChild ? ret.fullCommit() : ret; }
rollback() { return this.parent ?? this; }
setTransient<T>(identity: symbol, data: T): T { this.transientData[identity] = data as any; return data; }
/** Set transient data, which will only exist within the scope of the current statement */ getTransient<T>(identity: symbol): T { return this.transientData[identity] as T; }
clearTransientData(): void { this.transientData = {}; }}
pg_mem

Version Info

Tagged at
3 months ago