deno.land / x / pg_mem@2.8.1 / schema / readonly-table.ts

readonly-table.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import { _ITable, _ISelection, _ISchema, _Transaction, _IIndex, IValue, NotSupported, PermissionDeniedError, _Column, SchemaField, IndexDef, _Explainer, _SelectExplanation, _IType, ChangeHandler, Stats, DropHandler, IndexHandler, RegClass, RegType, Reg, _IConstraint, TruncateHandler } from '../interfaces-private.ts';import { CreateColumnDef, ExprRef, TableConstraint } from 'https://deno.land/x/pgsql_ast_parser@12.0.1/mod.ts';import { DataSourceBase } from '../transforms/transform-base.ts';import { Schema, ColumnNotFound, nil, ISubscription, ColumnDef } from '../interfaces.ts';import { buildAlias } from '../transforms/alias.ts';import { columnEvaluator } from '../transforms/selection.ts';import { colByName, findTemplate } from '../utils.ts';
export abstract class ReadOnlyTable<T = any> extends DataSourceBase<T> implements _ITable, _ISelection {

get isExecutionWithNoResult(): boolean { return false; }
get primaryIndex(): nil | IndexDef { return null; }
getColumns(): Iterable<ColumnDef> { throw new Error('Method not implemented on schema tables.'); }
abstract entropy(t: _Transaction): number; abstract enumerate(t: _Transaction): Iterable<T>; abstract hasItem(value: T, t: _Transaction): boolean; abstract readonly _schema: Schema;
reg!: Reg;
readonly selection: _ISelection = buildAlias(this); readonly hidden = true;
isOriginOf(v: IValue): boolean { return v.origin === this || v.origin === this.selection; }

get type() { return 'table' as const; }
constructor(private schema: _ISchema) { super(schema); }
get name(): string { return this._schema.name; }
register() { this.reg = this.schema._reg_register(this); }
private columnsById = new Map<string, IValue>(); private _columns?: IValue[];

private build() { if (this._columns) { return; } this._columns = []; for (const _col of this._schema.fields) { const newCol = columnEvaluator(this, _col.name, _col.type as _IType); this._columns.push(newCol); this.columnsById.set(_col.name, newCol); } }
get columns(): ReadonlyArray<IValue<any>> { this.build(); return this._columns!; }
getColumn(column: string | ExprRef): IValue; getColumn(column: string | ExprRef, nullIfNotFound?: boolean): IValue | nil; getColumn(column: string | ExprRef, nullIfNotFound?: boolean): IValue<any> | nil { this.build(); if (typeof column !== 'string' && column.table) { if (!column.table.schema && column.table.name !== this.name) { return null; } column = column.name; } return colByName(this.columnsById, column, nullIfNotFound); }
explain(e: _Explainer): _SelectExplanation { throw new PermissionDeniedError(this.name); }
listIndices(): IndexDef[] { return []; }
stats(t: _Transaction): Stats | null { throw new NotSupported('stats (count, ...) on information schema'); }
rename(to: string): this { throw new PermissionDeniedError(this.name); } update(t: _Transaction, toUpdate: any) { throw new PermissionDeniedError(this.name); } addColumn(column: SchemaField | CreateColumnDef): _Column { throw new PermissionDeniedError(this.name); } getColumnRef(column: string, nullIfNotFound?: boolean): _Column { throw new PermissionDeniedError(this.name); } getConstraint(constraint: string): _IConstraint | nil { return null; } addConstraint(constraint: TableConstraint, t: _Transaction): _IConstraint { throw new PermissionDeniedError(this.name); } insert(item: any) { throw new PermissionDeniedError(this.name); } doInsert(toInsert: any): void { throw new PermissionDeniedError(this.name); } delete(t: _Transaction, toDelete: T): void { throw new PermissionDeniedError(this.name); } truncate(t: _Transaction): void { throw new PermissionDeniedError(this.name); }
createIndex(): _IConstraint { throw new PermissionDeniedError(this.name); } dropIndex(t: _Transaction, name: string): void { throw new PermissionDeniedError(this.name); } setHidden(): this { throw new PermissionDeniedError(this.name); } drop(t: _Transaction): void { throw new PermissionDeniedError(this.name); }
setReadonly(): this { return this; }
getIndex(...forValue: IValue[]): _IIndex<any> | nil { return null; }
on(): any { throw new NotSupported('subscribing information schema'); } onBeforeChange(columns: string[], check: ChangeHandler<T>) { // nop return { unsubscribe() { } } } onCheckChange(columns: string[], check: ChangeHandler<T>) { // nop return { unsubscribe() { } } } onTruncate(sub: TruncateHandler): ISubscription { // nop return { unsubscribe() { } } } onDrop(sub: DropHandler): ISubscription { // nop return { unsubscribe() { } } } onIndex(sub: IndexHandler): ISubscription { // nop return { unsubscribe() { } } }

find(template?: T, columns?: (keyof T)[]): Iterable<T> { return findTemplate(this.selection, this.db.data, template, columns); }

make(table: _ITable, i: number, t: IValue<any>): any { throw new Error('not implemented'); }

*itemsByTable(table: string | _ITable, t: _Transaction): IterableIterator<any> { if (typeof table === 'string') { for (const s of this.db.listSchemas()) { const got = s.getTable(table, true); if (got) { yield* this.itemsByTable(got, t); } } } else { let i = 0; for (const f of table.selection.columns) { yield this.make(table, ++i, f); } } }}
pg_mem

Version Info

Tagged at
4 months ago