rake-db 1.3.2 → 2.0.0

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.
Files changed (72) hide show
  1. package/.env +3 -0
  2. package/.env.local +1 -0
  3. package/README.md +1 -545
  4. package/db.ts +16 -0
  5. package/dist/index.d.ts +94 -0
  6. package/dist/index.esm.js +190 -0
  7. package/dist/index.esm.js.map +1 -0
  8. package/dist/index.js +201 -0
  9. package/dist/index.js.map +1 -0
  10. package/jest-setup.ts +3 -0
  11. package/migrations/20221009210157_first.ts +8 -0
  12. package/migrations/20221009210200_second.ts +5 -0
  13. package/package.json +55 -41
  14. package/rollup.config.js +3 -0
  15. package/src/commands/createOrDrop.test.ts +145 -0
  16. package/src/commands/createOrDrop.ts +107 -0
  17. package/src/commands/generate.test.ts +133 -0
  18. package/src/commands/generate.ts +85 -0
  19. package/src/commands/migrateOrRollback.test.ts +118 -0
  20. package/src/commands/migrateOrRollback.ts +108 -0
  21. package/src/common.test.ts +281 -0
  22. package/src/common.ts +224 -0
  23. package/src/index.ts +2 -0
  24. package/src/migration/change.ts +20 -0
  25. package/src/migration/changeTable.test.ts +417 -0
  26. package/src/migration/changeTable.ts +375 -0
  27. package/src/migration/createTable.test.ts +269 -0
  28. package/src/migration/createTable.ts +169 -0
  29. package/src/migration/migration.test.ts +341 -0
  30. package/src/migration/migration.ts +296 -0
  31. package/src/migration/migrationUtils.ts +281 -0
  32. package/src/rakeDb.ts +29 -0
  33. package/src/test-utils.ts +45 -0
  34. package/tsconfig.json +12 -0
  35. package/dist/lib/createAndDrop.d.ts +0 -2
  36. package/dist/lib/createAndDrop.js +0 -63
  37. package/dist/lib/defaults.d.ts +0 -2
  38. package/dist/lib/defaults.js +0 -5
  39. package/dist/lib/errorCodes.d.ts +0 -4
  40. package/dist/lib/errorCodes.js +0 -7
  41. package/dist/lib/generate.d.ts +0 -1
  42. package/dist/lib/generate.js +0 -99
  43. package/dist/lib/help.d.ts +0 -2
  44. package/dist/lib/help.js +0 -24
  45. package/dist/lib/init.d.ts +0 -2
  46. package/dist/lib/init.js +0 -276
  47. package/dist/lib/migrate.d.ts +0 -4
  48. package/dist/lib/migrate.js +0 -189
  49. package/dist/lib/migration.d.ts +0 -37
  50. package/dist/lib/migration.js +0 -159
  51. package/dist/lib/schema/changeTable.d.ts +0 -23
  52. package/dist/lib/schema/changeTable.js +0 -109
  53. package/dist/lib/schema/column.d.ts +0 -31
  54. package/dist/lib/schema/column.js +0 -201
  55. package/dist/lib/schema/createTable.d.ts +0 -10
  56. package/dist/lib/schema/createTable.js +0 -53
  57. package/dist/lib/schema/foreignKey.d.ts +0 -11
  58. package/dist/lib/schema/foreignKey.js +0 -53
  59. package/dist/lib/schema/index.d.ts +0 -3
  60. package/dist/lib/schema/index.js +0 -54
  61. package/dist/lib/schema/primaryKey.d.ts +0 -9
  62. package/dist/lib/schema/primaryKey.js +0 -24
  63. package/dist/lib/schema/table.d.ts +0 -43
  64. package/dist/lib/schema/table.js +0 -110
  65. package/dist/lib/schema/timestamps.d.ts +0 -3
  66. package/dist/lib/schema/timestamps.js +0 -9
  67. package/dist/lib/utils.d.ts +0 -26
  68. package/dist/lib/utils.js +0 -114
  69. package/dist/rake-db.d.ts +0 -2
  70. package/dist/rake-db.js +0 -34
  71. package/dist/types.d.ts +0 -94
  72. package/dist/types.js +0 -40
@@ -1,201 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Column = void 0;
4
- class Column {
5
- constructor(action, name, options = {}, _type) {
6
- this.action = action;
7
- this.name = name;
8
- this.options = options;
9
- this._type = _type;
10
- }
11
- primaryKey() {
12
- this.options = { ...this.options, primaryKey: true };
13
- return this;
14
- }
15
- type(type) {
16
- this.options = { ...this.options, type };
17
- return this;
18
- }
19
- default(value) {
20
- this.options = { ...this.options, default: value };
21
- return this;
22
- }
23
- required() {
24
- this.options = { ...this.options, null: false };
25
- return this;
26
- }
27
- optional() {
28
- this.options = { ...this.options, null: true };
29
- return this;
30
- }
31
- index(options) {
32
- this.options = { ...this.options, index: options !== null && options !== void 0 ? options : true };
33
- return this;
34
- }
35
- comment(comment) {
36
- this.options = { ...this.options, comment };
37
- return this;
38
- }
39
- mode(mode) {
40
- this.options = { ...this.options, mode };
41
- return this;
42
- }
43
- unique() {
44
- if (typeof this.options.index === 'object') {
45
- this.options = {
46
- ...this.options,
47
- index: { ...this.options.index, unique: true },
48
- };
49
- }
50
- else {
51
- this.options = { ...this.options, index: { unique: true } };
52
- }
53
- return this;
54
- }
55
- length(length) {
56
- this.options = { ...this.options, length };
57
- return this;
58
- }
59
- precision(precision) {
60
- this.options = { ...this.options, precision };
61
- return this;
62
- }
63
- scale(scale) {
64
- this.options = { ...this.options, scale };
65
- return this;
66
- }
67
- collate(collate) {
68
- this.options = { ...this.options, collate };
69
- return this;
70
- }
71
- using(using) {
72
- this.options = { ...this.options, using };
73
- return this;
74
- }
75
- references(table, column) {
76
- this.options = { ...this.options, references: { table, column } };
77
- return this;
78
- }
79
- column(column) {
80
- if (!this.options.references) {
81
- throw new Error('Please specify table for references');
82
- }
83
- this.options = {
84
- ...this.options,
85
- references: { ...this.options.references, column },
86
- };
87
- return this;
88
- }
89
- onUpdate(action) {
90
- if (!this.options.references) {
91
- throw new Error('Please specify table for references');
92
- }
93
- this.options = {
94
- ...this.options,
95
- references: { ...this.options.references, onUpdate: action },
96
- };
97
- return this;
98
- }
99
- onDelete(action) {
100
- if (!this.options.references) {
101
- throw new Error('Please specify table for references');
102
- }
103
- this.options = {
104
- ...this.options,
105
- references: { ...this.options.references, onDelete: action },
106
- };
107
- return this;
108
- }
109
- toSql(table) {
110
- const { action, options, name } = this;
111
- if (action === 'drop') {
112
- const sql = ['DROP COLUMN', `"${name}"`];
113
- let { mode } = options;
114
- if (mode) {
115
- mode = mode.toUpperCase();
116
- sql.push(mode);
117
- }
118
- else {
119
- sql.push('CASCADE');
120
- }
121
- return sql.join(' ');
122
- }
123
- if ('comment' in options && options.comment)
124
- table.comments.push([name, options.comment]);
125
- if (this.action === 'alter') {
126
- const sql = [];
127
- if ((this.options.type && options.default) || options.default === null)
128
- this.alterColumn(sql, name, 'DROP DEFAULT');
129
- if (options.type)
130
- this.alterColumn(sql, name, `TYPE ${this.getTypeSql(options.type)}`);
131
- if (options.default !== undefined && options.default !== null)
132
- this.alterColumn(sql, name, `SET DEFAULT ${options.default}`);
133
- if (options.null !== undefined)
134
- this.alterColumn(sql, name, options.null ? 'DROP NOT NULL' : 'SET NOT NULL');
135
- if ((!table.reverse && options.index) ||
136
- (table.reverse && options.index === false)) {
137
- table.index(name, options.index || options);
138
- }
139
- else if ((!table.reverse && options.index === false) ||
140
- (table.reverse && options.index)) {
141
- ;
142
- table.dropIndex(name, options.index || options);
143
- }
144
- return sql;
145
- }
146
- const sql = [
147
- this.action === 'create' ? `"${name}"` : `ADD COLUMN "${name}"`,
148
- ];
149
- const type = options.type || this._type;
150
- if (!type)
151
- throw new Error('Type is not specified');
152
- sql.push(this.getTypeSql(type));
153
- if (options.primaryKey)
154
- sql.push('PRIMARY KEY');
155
- if (options.null === false)
156
- sql.push('NOT NULL');
157
- if (options.default !== undefined)
158
- sql.push(`DEFAULT ${options.default}`);
159
- const { references } = options;
160
- if (references) {
161
- sql.push(`REFERENCES "${references.table}"`);
162
- if (references.column)
163
- sql.push(`("${references.column}")`);
164
- if (references.onUpdate)
165
- sql.push(`ON UPDATE ${references.onUpdate}`);
166
- if (references.onDelete)
167
- sql.push(`ON DELETE ${references.onDelete}`);
168
- }
169
- if (options.unique) {
170
- if (options.index === true || !options.index)
171
- options.index = { unique: true };
172
- else
173
- options.index.unique = true;
174
- }
175
- if (options.index) {
176
- table.index(name, options.index);
177
- }
178
- return sql.join(' ');
179
- }
180
- alterColumn(arr, name, sql) {
181
- arr.push(`ALTER COLUMN "${name}" ${sql}`);
182
- }
183
- getTypeSql(type) {
184
- const { options } = this;
185
- const sql = [type];
186
- if (options.length)
187
- sql.push(`(${options.length})`);
188
- else if (options.precision !== undefined && options.scale === undefined)
189
- sql.push(`(${options.precision})`);
190
- else if (options.precision === undefined && options.scale !== undefined)
191
- sql.push(`(${options.scale})`);
192
- else if (options.precision !== undefined && options.scale !== undefined)
193
- sql.push(`(${options.precision}, ${options.scale})`);
194
- if (options.collate)
195
- sql.push('COLLATE', options.collate);
196
- if (options.using)
197
- sql.push('USING', options.using);
198
- return sql.join(' ');
199
- }
200
- }
201
- exports.Column = Column;
@@ -1,10 +0,0 @@
1
- import Table from './table';
2
- import { ForeignKeyFunction, Migration, TableCallback, TableOptions } from '../../types';
3
- import { PrimaryKey } from './primaryKey';
4
- export declare class CreateTable extends Table {
5
- constructor(tableName: string, reverse: boolean, options?: TableOptions);
6
- foreignKey: ForeignKeyFunction;
7
- constraint: (name: string, sql?: string | undefined) => void;
8
- primaryKey: (columns: string[], name?: string | undefined) => PrimaryKey;
9
- __commit: (db: Migration, fn?: TableCallback | undefined) => void;
10
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CreateTable = void 0;
7
- const table_1 = __importDefault(require("./table"));
8
- const index_1 = require("./index");
9
- const utils_1 = require("../utils");
10
- const foreignKey_1 = require("./foreignKey");
11
- const primaryKey_1 = require("./primaryKey");
12
- class CreateTable extends table_1.default {
13
- constructor(tableName, reverse, options = {}) {
14
- super(tableName, reverse, options);
15
- this.foreignKey = (options) => {
16
- const fkey = new foreignKey_1.ForeignKey('createTable', this, this.reverse, options);
17
- this.lines.push(fkey);
18
- return fkey;
19
- };
20
- this.constraint = (name, sql) => this.execute(`CONSTRAINT ${sql ? `"${name}" ${sql}` : name}`);
21
- this.primaryKey = (columns, name) => {
22
- const pkey = new primaryKey_1.PrimaryKey('create', columns, name);
23
- this.lines.push(pkey);
24
- return pkey;
25
- };
26
- this.__commit = (db, fn) => {
27
- if (fn)
28
- fn(this);
29
- const sql = [];
30
- sql.push(`CREATE TABLE "${this.tableName}" (`);
31
- if (this.lines.length) {
32
- sql.push('\n ' +
33
- this.lines
34
- .map((item) => (typeof item === 'string' ? item : item.toSql(this)))
35
- .filter((string) => string)
36
- .join(',\n '));
37
- }
38
- sql.push('\n)');
39
- db.exec(sql.join('')).catch(utils_1.noop);
40
- for (const args of this.indices) {
41
- const [create, column, options] = args;
42
- if (create)
43
- db.exec(index_1.addIndex(this.tableName, column, options)).catch(utils_1.noop);
44
- }
45
- this.addComments(db);
46
- };
47
- if (options.id !== false) {
48
- this.reverse = false;
49
- this.serial('id', { primaryKey: true });
50
- }
51
- }
52
- }
53
- exports.CreateTable = CreateTable;
@@ -1,11 +0,0 @@
1
- import { ForeignKeyOptions } from '../../types';
2
- import { CreateTable } from './createTable';
3
- import { ChangeTable } from './changeTable';
4
- export declare class ForeignKey {
5
- action: 'createTable' | 'changeTable';
6
- table: CreateTable | ChangeTable;
7
- reverse: boolean;
8
- options: ForeignKeyOptions;
9
- constructor(action: 'createTable' | 'changeTable', table: CreateTable | ChangeTable, reverse: boolean, options: ForeignKeyOptions);
10
- toSql(): undefined | string;
11
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ForeignKey = void 0;
4
- const utils_1 = require("../utils");
5
- class ForeignKey {
6
- constructor(action, table, reverse, options) {
7
- this.action = action;
8
- this.table = table;
9
- this.reverse = reverse;
10
- this.options = options;
11
- }
12
- toSql() {
13
- const { action, table, reverse, options } = this;
14
- if (action === 'createTable' && reverse) {
15
- return;
16
- }
17
- else if (action === 'changeTable' &&
18
- reverse &&
19
- (Array.isArray(options.column)
20
- ? options.column.some((col) => table.removedColumns.includes(col))
21
- : table.removedColumns.includes(options.column))) {
22
- return;
23
- }
24
- const name = options.name ||
25
- (Array.isArray(options.column)
26
- ? utils_1.join(table.tableName, ...options.column, 'fkey')
27
- : utils_1.join(table.tableName, options.column, 'fkey'));
28
- const columns = Array.isArray(options.column)
29
- ? options.column.map((col) => `"${col}"`).join(', ')
30
- : `"${options.column}"`;
31
- const foreignColumns = Array.isArray(options.references)
32
- ? options.references.map((col) => `"${col}"`).join(', ')
33
- : `"${options.references}"`;
34
- const onUpdate = options.onUpdate ? ` ON UPDATE ${options.onUpdate}` : '';
35
- const onDelete = options.onDelete ? ` ON DELETE ${options.onDelete}` : '';
36
- const prefix = action === 'createTable' ? '' : reverse ? 'DROP' : 'ADD';
37
- const sql = [prefix, `CONSTRAINT "${name}"`];
38
- if (action !== 'changeTable' || !reverse) {
39
- sql.push(`FOREIGN KEY (${columns}) REFERENCES "${options.table}"(${foreignColumns})${onUpdate}${onDelete}`);
40
- }
41
- if (action === 'changeTable' && reverse) {
42
- sql.push('CASCADE');
43
- }
44
- if (options.index) {
45
- if (reverse !== table.reverse && table.dropIndex)
46
- table.dropIndex(options.column, options.index);
47
- else
48
- table.index(options.column, options.index);
49
- }
50
- return sql.join(' ');
51
- }
52
- }
53
- exports.ForeignKey = ForeignKey;
@@ -1,3 +0,0 @@
1
- import { IndexOptions } from '../../types';
2
- export declare const addIndex: (table: string, column: string | string[], options?: true | IndexOptions) => string;
3
- export declare const dropIndex: (table: string, column: string | string[], options?: true | IndexOptions) => string;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dropIndex = exports.addIndex = void 0;
4
- const utils_1 = require("../utils");
5
- const getIndexName = (table, column, options = {}) => (options !== true && options.name) ||
6
- utils_1.join(table, Array.isArray(column) ? utils_1.join(...column) : column, 'index');
7
- const getIndexColumns = (table, column, options = {}) => {
8
- if (Array.isArray(column))
9
- return column.map((col) => getIndexColumns(table, col, options)).join(', ');
10
- else {
11
- let sql = `"${column}"`;
12
- if (options.expression)
13
- sql += `(${options.expression})`;
14
- if (options.order)
15
- sql += ` ${options.order}`;
16
- return sql;
17
- }
18
- };
19
- const addIndex = (table, column, options = {}) => {
20
- if (options === true)
21
- options = {};
22
- const sql = ['CREATE'];
23
- if (options.unique)
24
- sql.push('UNIQUE');
25
- sql.push('INDEX');
26
- const indexName = getIndexName(table, column, options);
27
- sql.push(`"${indexName}"`);
28
- sql.push('ON', `"${table}"`);
29
- if (options.using)
30
- sql.push('USING', options.using);
31
- sql.push(`(${getIndexColumns(table, column, options)})`);
32
- if (options.including)
33
- sql.push('INCLUDING', `(${Array.isArray(options.including)
34
- ? options.including.join(', ')
35
- : options.including})`);
36
- if (options.with)
37
- sql.push('WITH', `(${options.with})`);
38
- if (options.tablespace)
39
- sql.push('TABLESPACE', options.tablespace);
40
- if (options.where)
41
- sql.push('WHERE', options.where);
42
- return sql.join(' ');
43
- };
44
- exports.addIndex = addIndex;
45
- const dropIndex = (table, column, options = {}) => {
46
- const sql = ['DROP INDEX', `"${getIndexName(table, column, options)}"`];
47
- let mode = options !== true && options.mode;
48
- if (mode) {
49
- mode = mode.toUpperCase();
50
- sql.push(mode);
51
- }
52
- return sql.join(' ');
53
- };
54
- exports.dropIndex = dropIndex;
@@ -1,9 +0,0 @@
1
- import { CreateTable } from './createTable';
2
- import { ChangeTable } from './changeTable';
3
- export declare class PrimaryKey {
4
- action: 'create' | 'add' | 'drop';
5
- columns: string[];
6
- name?: string | undefined;
7
- constructor(action: 'create' | 'add' | 'drop', columns: string[], name?: string | undefined);
8
- toSql(table: CreateTable | ChangeTable): string;
9
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrimaryKey = void 0;
4
- class PrimaryKey {
5
- constructor(action, columns, name) {
6
- this.action = action;
7
- this.columns = columns;
8
- this.name = name;
9
- }
10
- toSql(table) {
11
- const { action, name } = this;
12
- const drop = (!table.reverse && action === 'drop') ||
13
- (table.reverse && action === 'add');
14
- if (drop) {
15
- return `DROP CONSTRAINT "${name || `${table.tableName}_pkey`}"`;
16
- }
17
- const columns = `(${this.columns
18
- .map((column) => `"${column}"`)
19
- .join(', ')})`;
20
- const constraint = name ? `CONSTRAINT "${name}" ` : '';
21
- return `${action === 'create' ? '' : 'ADD '}${constraint}PRIMARY KEY ${columns}`;
22
- }
23
- }
24
- exports.PrimaryKey = PrimaryKey;
@@ -1,43 +0,0 @@
1
- import { Column } from './column';
2
- import { Migration, ColumnFunction, ColumnOptions, IndexOptions, TableOptions, ColumnTypes } from '../../types';
3
- import { ForeignKey } from './foreignKey';
4
- import { PrimaryKey } from './primaryKey';
5
- declare type ColumnMethods = {
6
- [key in keyof typeof ColumnTypes]: (name: string, options?: ColumnOptions) => Column;
7
- };
8
- export default class Table implements ColumnMethods {
9
- tableName: string;
10
- reverse: boolean;
11
- options: TableOptions;
12
- lines: (string | Column | ForeignKey | PrimaryKey)[];
13
- indices: [boolean, string | string[], undefined | true | IndexOptions][];
14
- comments: [string, string][];
15
- constraint: (name: string, sql?: string) => void;
16
- removedColumns: string[];
17
- constructor(tableName: string, reverse: boolean, options?: TableOptions);
18
- execute(sql: string): void;
19
- column: ColumnFunction;
20
- index: (column: string | string[], options?: true | IndexOptions | undefined) => void;
21
- timestamps: (options?: ColumnOptions | undefined) => void;
22
- addComments: (db: Migration) => void;
23
- bigint(name: string, options?: ColumnOptions): Column;
24
- bigserial(name: string, options?: ColumnOptions): Column;
25
- boolean(name: string, options?: ColumnOptions): Column;
26
- date(name: string, options?: ColumnOptions): Column;
27
- decimal(name: string, options?: ColumnOptions): Column;
28
- float(name: string, options?: ColumnOptions): Column;
29
- integer(name: string, options?: ColumnOptions): Column;
30
- text(name: string, options?: ColumnOptions): Column;
31
- smallint(name: string, options?: ColumnOptions): Column;
32
- smallserial(name: string, options?: ColumnOptions): Column;
33
- varchar(name: string, options?: ColumnOptions): Column;
34
- string(name: string, options?: ColumnOptions): Column;
35
- time(name: string, options?: ColumnOptions): Column;
36
- timestamp(name: string, options?: ColumnOptions): Column;
37
- timestamptz(name: string, options?: ColumnOptions): Column;
38
- binary(name: string, options?: ColumnOptions): Column;
39
- serial(name: string, options?: ColumnOptions): Column;
40
- json(name: string, options?: ColumnOptions): Column;
41
- jsonb(name: string, options?: ColumnOptions): Column;
42
- }
43
- export {};
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const pg_adapter_1 = require("pg-adapter");
7
- const column_1 = require("./column");
8
- const timestamps_1 = __importDefault(require("./timestamps"));
9
- const utils_1 = require("../utils");
10
- class Table {
11
- constructor(tableName, reverse, options = {}) {
12
- this.removedColumns = [];
13
- this.column = (name, type, options = {}) => {
14
- if (this.reverse) {
15
- this.removedColumns.push(name);
16
- const column = new column_1.Column('drop', name, options, type);
17
- this.lines.push(column);
18
- return column;
19
- }
20
- const column = new column_1.Column('create', name, options, type);
21
- this.lines.push(column);
22
- return column;
23
- };
24
- this.index = (column, options) => {
25
- if (this.reverse &&
26
- (Array.isArray(column)
27
- ? column.some((col) => this.removedColumns.includes(col))
28
- : this.removedColumns.includes(column)))
29
- return;
30
- this.indices.push([!this.reverse, column, options]);
31
- };
32
- this.timestamps = (options) => timestamps_1.default(this.column, options);
33
- this.addComments = (db) => {
34
- if (this.reverse)
35
- return;
36
- const { tableName, comments } = this;
37
- if ('comment' in this.options)
38
- db.exec(`COMMENT ON TABLE "${tableName}" IS ${pg_adapter_1.quote(this.options.comment)}`).catch(utils_1.noop);
39
- for (const [column, message] of comments)
40
- db.exec(`COMMENT ON COLUMN "${tableName}"."${column}" IS ${pg_adapter_1.quote(message)}`).catch(utils_1.noop);
41
- };
42
- this.tableName = tableName;
43
- this.reverse = reverse;
44
- this.options = options;
45
- this.lines = [];
46
- this.indices = [];
47
- this.comments = [];
48
- }
49
- execute(sql) {
50
- this.lines.push(sql);
51
- }
52
- bigint(name, options) {
53
- return this.column(name, 'bigint', options);
54
- }
55
- bigserial(name, options) {
56
- return this.column(name, 'bigserial', options);
57
- }
58
- boolean(name, options) {
59
- return this.column(name, 'boolean', options);
60
- }
61
- date(name, options) {
62
- return this.column(name, 'date', options);
63
- }
64
- decimal(name, options) {
65
- return this.column(name, 'decimal', options);
66
- }
67
- float(name, options) {
68
- return this.column(name, 'float8', options);
69
- }
70
- integer(name, options) {
71
- return this.column(name, 'integer', options);
72
- }
73
- text(name, options) {
74
- return this.column(name, 'text', options);
75
- }
76
- smallint(name, options) {
77
- return this.column(name, 'smallint', options);
78
- }
79
- smallserial(name, options) {
80
- return this.column(name, 'smallserial', options);
81
- }
82
- varchar(name, options) {
83
- return this.column(name, 'varchar', options);
84
- }
85
- string(name, options) {
86
- return this.column(name, 'text', options);
87
- }
88
- time(name, options) {
89
- return this.column(name, 'time', options);
90
- }
91
- timestamp(name, options) {
92
- return this.column(name, 'timestamp', options);
93
- }
94
- timestamptz(name, options) {
95
- return this.column(name, 'timestamptz', options);
96
- }
97
- binary(name, options) {
98
- return this.column(name, 'bytea', options);
99
- }
100
- serial(name, options) {
101
- return this.column(name, 'serial', options);
102
- }
103
- json(name, options) {
104
- return this.column(name, 'json', options);
105
- }
106
- jsonb(name, options) {
107
- return this.column(name, 'jsonb', options);
108
- }
109
- }
110
- exports.default = Table;
@@ -1,3 +0,0 @@
1
- import { ColumnFunction, ColumnOptions } from '../../types';
2
- declare const _default: (column: ColumnFunction, options?: ColumnOptions) => void;
3
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../utils");
4
- exports.default = (column, options = {}) => {
5
- if (options.default === undefined)
6
- options.default = 'now()';
7
- column(utils_1.join('created', 'at'), 'timestamp', options);
8
- column(utils_1.join('updated', 'at'), 'timestamp', options);
9
- };
@@ -1,26 +0,0 @@
1
- import { Adapter } from 'pg-adapter';
2
- export declare type Creds = {
3
- database: string;
4
- user: string;
5
- password: string;
6
- host: string;
7
- port: number;
8
- };
9
- declare let camelCase: boolean;
10
- export declare const noop: () => void;
11
- export declare const join: (...args: string[]) => string;
12
- export declare const mkdirRecursive: (inputPath: string) => void;
13
- export declare const getConfig: () => {
14
- camelCase: boolean;
15
- migrationsPath: string;
16
- configs: Creds[];
17
- };
18
- export declare const askAdminCreds: ({ user, password }?: {
19
- user: string;
20
- password: string;
21
- }) => Promise<{
22
- user: string;
23
- password: string;
24
- }>;
25
- export declare const createSchemaMigrations: (db: Adapter) => Promise<void>;
26
- export {};