deno.land / x / pg_mem@2.8.1 / execution / schema-amends / create-table.ts

create-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
import { _ISchema, _Transaction, SchemaField, NotSupported, _ITable, _IStatementExecutor, Schema, DataType, QueryError } from '../../interfaces-private.ts';import { CreateTableStatement, QName } from 'https://deno.land/x/pgsql_ast_parser@12.0.1/mod.ts';import { ignore, Optional } from '../../utils.ts';import { checkExistence, ExecHelper } from '../exec-utils.ts';import { buildCtx } from '../../parser/context.ts';
export class ExecuteCreateTable extends ExecHelper implements _IStatementExecutor { private toDeclare: Schema; private ifNotExists: boolean; private name: QName; private schema: _ISchema;
constructor(p: CreateTableStatement) { super(p); const { db } = buildCtx(); this.schema = db.getSchema(p.name.schema); let fields: SchemaField[] = []; for (const f of p.columns) { switch (f.kind) { case 'column': if (!f.dataType.kind && f.dataType.name === DataType.record) { throw new QueryError(`column "${f.name.name}" has pseudo-type record`, '42P16'); } // TODO: #collation ignore(f.collate); const nf = { ...f, name: f.name.name, type: this.schema.getType(f.dataType), serial: !f.dataType.kind && (f.dataType.name === 'serial' || f.dataType.name === 'bigserial'), }; delete (nf as Optional<typeof nf>).dataType; fields.push(nf); break; case 'like table': throw new NotSupported('"like table" statement'); default: throw NotSupported.never(f); } } this.ifNotExists = !!p.ifNotExists; this.name = p.name; this.toDeclare = { name: p.name.name, constraints: p.constraints, fields, }; }
execute(t: _Transaction) {
// commit pending data before making changes // (because the creation does not support further rollbacks) t = t.fullCommit();
// perform creation checkExistence(this.schema, this.name, this.ifNotExists, () => { this.schema.declareTable(this.toDeclare); });

// new implicit transaction t = t.fork(); return this.noData(t, 'CREATE'); }}
pg_mem

Version Info

Tagged at
a year ago