orchid-orm 1.3.15 → 1.4.16

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 (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/index.d.ts +59 -54
  3. package/dist/index.esm.js +777 -547
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +776 -546
  6. package/dist/index.js.map +1 -1
  7. package/jest-setup.ts +4 -0
  8. package/package.json +8 -4
  9. package/src/appCodeUpdater/appCodeUpdater.ts +19 -0
  10. package/src/appCodeUpdater/fileChanges.ts +41 -0
  11. package/src/appCodeUpdater/testUtils.ts +31 -0
  12. package/src/appCodeUpdater/tsUtils.ts +137 -0
  13. package/src/appCodeUpdater/updateMainFile.test.ts +230 -0
  14. package/src/appCodeUpdater/updateMainFile.ts +163 -0
  15. package/src/appCodeUpdater/updateTableFile.ts +19 -0
  16. package/src/index.ts +5 -1
  17. package/src/orm.test.ts +13 -13
  18. package/src/orm.ts +21 -21
  19. package/src/relations/belongsTo.test.ts +1 -1
  20. package/src/relations/belongsTo.ts +291 -186
  21. package/src/relations/hasAndBelongsToMany.test.ts +1 -1
  22. package/src/relations/hasAndBelongsToMany.ts +292 -218
  23. package/src/relations/hasMany.test.ts +16 -10
  24. package/src/relations/hasMany.ts +243 -172
  25. package/src/relations/hasOne.test.ts +10 -10
  26. package/src/relations/hasOne.ts +211 -138
  27. package/src/relations/relations.ts +85 -77
  28. package/src/relations/utils.ts +154 -4
  29. package/src/repo.test.ts +29 -29
  30. package/src/repo.ts +6 -6
  31. package/src/{model.test.ts → table.test.ts} +15 -15
  32. package/src/{model.ts → table.ts} +17 -17
  33. package/src/test-utils/test-db.ts +15 -15
  34. package/src/test-utils/{test-models.ts → test-tables.ts} +42 -42
  35. package/src/transaction.test.ts +1 -1
  36. package/src/transaction.ts +4 -4
  37. package/src/utils.ts +9 -0
  38. package/tsconfig.json +1 -0
@@ -0,0 +1,41 @@
1
+ export class FileChanges {
2
+ private ranges: ([from: number, to: number] | string)[] = [];
3
+
4
+ constructor(public content: string) {}
5
+
6
+ add(at: number, text: string, end = at) {
7
+ if (this.ranges.length === 0) {
8
+ this.ranges.push([0, at], text, [end, this.content.length]);
9
+ } else {
10
+ const last = this.ranges[this.ranges.length - 1] as [number, number];
11
+ last[1] = at;
12
+ this.ranges.push(text, [end, this.content.length]);
13
+ }
14
+ }
15
+
16
+ replace(from: number, to: number, text: string) {
17
+ this.add(from, text, to);
18
+ }
19
+
20
+ remove(from: number, to: number) {
21
+ if (this.ranges.length === 0) {
22
+ this.ranges.push([0, from], [to, this.content.length]);
23
+ } else {
24
+ const last = this.ranges[this.ranges.length - 1] as [number, number];
25
+ last[1] = from;
26
+ this.ranges.push([to, this.content.length]);
27
+ }
28
+ }
29
+
30
+ apply() {
31
+ return this.ranges.length
32
+ ? this.ranges
33
+ .map((item) =>
34
+ typeof item === 'string'
35
+ ? item
36
+ : this.content.slice(item[0], item[1]),
37
+ )
38
+ .join('')
39
+ : this.content;
40
+ }
41
+ }
@@ -0,0 +1,31 @@
1
+ import { RakeDbAst } from 'rake-db';
2
+ import { columnTypes } from 'pqb';
3
+
4
+ const makeAst = () => {
5
+ const addTable: RakeDbAst.Table = {
6
+ type: 'table',
7
+ action: 'create',
8
+ name: 'table',
9
+ shape: {
10
+ id: columnTypes.serial().primaryKey(),
11
+ },
12
+ noPrimaryKey: 'ignore',
13
+ indexes: [],
14
+ foreignKeys: [],
15
+ };
16
+
17
+ const dropTable: RakeDbAst.Table = {
18
+ ...addTable,
19
+ action: 'drop',
20
+ };
21
+
22
+ const renameTable: RakeDbAst.RenameTable = {
23
+ type: 'renameTable',
24
+ from: 'table',
25
+ to: 'renamedTable',
26
+ };
27
+
28
+ return { addTable, dropTable, renameTable };
29
+ };
30
+
31
+ export const ast = makeAst();
@@ -0,0 +1,137 @@
1
+ import {
2
+ CallExpression,
3
+ Expression,
4
+ ImportDeclaration,
5
+ NamedImports,
6
+ NodeArray,
7
+ ObjectLiteralElement,
8
+ ObjectLiteralExpression,
9
+ PropertyAssignment,
10
+ ShorthandPropertyAssignment,
11
+ Statement,
12
+ SyntaxKind,
13
+ VariableStatement,
14
+ } from 'typescript';
15
+ import path from 'path';
16
+
17
+ const iterate = <T>(
18
+ kind: number,
19
+ ): ((statements: NodeArray<Statement>) => Generator<T, void, unknown>) => {
20
+ return function* (statements: NodeArray<Statement>) {
21
+ for (const node of statements) {
22
+ if (node.kind === kind) {
23
+ yield node as T;
24
+ }
25
+ }
26
+ };
27
+ };
28
+
29
+ const isNode = <T extends { kind: number }>() => {
30
+ return <U extends T>(kind: number) => {
31
+ return (node?: T): node is U => {
32
+ return node?.kind === kind;
33
+ };
34
+ };
35
+ };
36
+
37
+ const isExpression = isNode<Expression>();
38
+ const isObjectLiteral = isNode<ObjectLiteralElement>();
39
+
40
+ export const ts = {
41
+ is: {
42
+ call: isExpression<CallExpression>(SyntaxKind.CallExpression),
43
+ objectLiteral: isExpression<ObjectLiteralExpression>(
44
+ SyntaxKind.ObjectLiteralExpression,
45
+ ),
46
+ propertyAssignment: isObjectLiteral<PropertyAssignment>(
47
+ SyntaxKind.PropertyAssignment,
48
+ ),
49
+ shorthandPropertyAssignment: isObjectLiteral<ShorthandPropertyAssignment>(
50
+ SyntaxKind.ShorthandPropertyAssignment,
51
+ ),
52
+ },
53
+ import: {
54
+ iterate: iterate<ImportDeclaration>(SyntaxKind.ImportDeclaration),
55
+ *iterateWithSource(statements: NodeArray<Statement>, path: string) {
56
+ for (const node of ts.import.iterate(statements)) {
57
+ if (ts.import.getSource(node) !== path) continue;
58
+ yield node;
59
+ }
60
+ },
61
+ getSource(node: ImportDeclaration) {
62
+ return node.moduleSpecifier.getText().slice(1, -1);
63
+ },
64
+ getEndPos(statements: NodeArray<Statement>) {
65
+ let end = 0;
66
+ for (const node of ts.import.iterate(statements)) {
67
+ end = node.end;
68
+ }
69
+ return end;
70
+ },
71
+ getStatementsImportedName(
72
+ statements: NodeArray<Statement>,
73
+ path: string,
74
+ key: string,
75
+ ) {
76
+ for (const node of ts.import.iterateWithSource(statements, path)) {
77
+ const name = ts.import.getImportName(node, key);
78
+ if (name) return name;
79
+ }
80
+
81
+ return;
82
+ },
83
+ getImportName(node: ImportDeclaration, key: string) {
84
+ if (!node.importClause) return;
85
+
86
+ const elements = (node.importClause.namedBindings as NamedImports)
87
+ ?.elements;
88
+
89
+ if (!elements) return;
90
+
91
+ for (const element of elements) {
92
+ if (
93
+ element.propertyName?.escapedText === key ||
94
+ element.name.escapedText === key
95
+ ) {
96
+ return element.name.escapedText.toString();
97
+ }
98
+ }
99
+
100
+ return;
101
+ },
102
+ },
103
+ variable: {
104
+ iterate: iterate<VariableStatement>(SyntaxKind.VariableStatement),
105
+ *iterateDeclarations(statements: NodeArray<Statement>) {
106
+ for (const node of ts.variable.iterate(statements)) {
107
+ for (const dec of node.declarationList.declarations) {
108
+ yield dec;
109
+ }
110
+ }
111
+ },
112
+ },
113
+ prop: {
114
+ getValue(prop: ObjectLiteralElement) {
115
+ if (ts.is.propertyAssignment(prop)) {
116
+ return prop.initializer.getText();
117
+ } else if (ts.is.shorthandPropertyAssignment(prop)) {
118
+ return prop.name.escapedText.toString();
119
+ } else {
120
+ return;
121
+ }
122
+ },
123
+ },
124
+ path: {
125
+ getRelative(from: string, to: string) {
126
+ const rel = path.relative(path.dirname(from), to);
127
+ return rel.startsWith('./') || rel.startsWith('../') ? rel : `./${rel}`;
128
+ },
129
+ },
130
+ spaces: {
131
+ getAtLine(content: string, pos: number) {
132
+ const lines = content.slice(0, pos).split('\n');
133
+ const last = lines[lines.length - 1];
134
+ return last.match(/^\s+/)?.[0] || '';
135
+ },
136
+ },
137
+ };
@@ -0,0 +1,230 @@
1
+ import { updateMainFile } from './updateMainFile';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs/promises';
4
+ import { ast } from './testUtils';
5
+
6
+ jest.mock('fs/promises', () => ({
7
+ readFile: jest.fn(),
8
+ writeFile: jest.fn(),
9
+ }));
10
+
11
+ const asMock = (fn: unknown) => fn as jest.Mock;
12
+
13
+ const mainFilePath = path.resolve('db.ts');
14
+ const tablePath = (table: string) => path.resolve(`tables/${table}`);
15
+
16
+ describe('updateMainFile', () => {
17
+ beforeEach(() => {
18
+ jest.resetAllMocks();
19
+ });
20
+
21
+ it('should throw when file is not found', async () => {
22
+ asMock(fs.readFile).mockRejectedValue(new Error());
23
+
24
+ await expect(() =>
25
+ updateMainFile(mainFilePath, tablePath, ast.addTable),
26
+ ).rejects.toThrow();
27
+ });
28
+
29
+ describe('add table', () => {
30
+ it('should add table', async () => {
31
+ asMock(fs.readFile).mockResolvedValue(`
32
+ import { orchidORM } from 'orchid-orm';
33
+
34
+ export const db = orchidORM({}, {});
35
+ `);
36
+
37
+ await updateMainFile(mainFilePath, tablePath, ast.addTable);
38
+
39
+ expect(fs.writeFile).toBeCalledWith(
40
+ mainFilePath,
41
+ `
42
+ import { orchidORM } from 'orchid-orm';
43
+ import { Table } from './tables/table';
44
+
45
+ export const db = orchidORM({}, {
46
+ table: Table,
47
+ });
48
+ `,
49
+ );
50
+ });
51
+
52
+ it('should handle import as', async () => {
53
+ asMock(fs.readFile).mockResolvedValue(`
54
+ import { orchidORM as custom } from 'orchid-orm';
55
+
56
+ export const db = custom({}, {});
57
+ `);
58
+
59
+ await updateMainFile(mainFilePath, tablePath, ast.addTable);
60
+
61
+ expect(fs.writeFile).toBeCalledWith(
62
+ mainFilePath,
63
+ `
64
+ import { orchidORM as custom } from 'orchid-orm';
65
+ import { Table } from './tables/table';
66
+
67
+ export const db = custom({}, {
68
+ table: Table,
69
+ });
70
+ `,
71
+ );
72
+ });
73
+
74
+ it('should handle object list with elements', async () => {
75
+ asMock(fs.readFile).mockResolvedValue(`
76
+ import { orchidORM } from 'orchid-orm';
77
+ import { Some } from './tables/some';
78
+
79
+ export const db = orchidORM({}, {
80
+ some: Some,
81
+ });
82
+ `);
83
+
84
+ await updateMainFile(mainFilePath, tablePath, ast.addTable);
85
+
86
+ expect(fs.writeFile).toBeCalledWith(
87
+ mainFilePath,
88
+ `
89
+ import { orchidORM } from 'orchid-orm';
90
+ import { Some } from './tables/some';
91
+ import { Table } from './tables/table';
92
+
93
+ export const db = orchidORM({}, {
94
+ some: Some,
95
+ table: Table,
96
+ });
97
+ `,
98
+ );
99
+ });
100
+
101
+ it('should handle object list without ending coma', async () => {
102
+ asMock(fs.readFile).mockResolvedValue(`
103
+ import { orchidORM } from 'orchid-orm';
104
+ import { Some } from './tables/some';
105
+
106
+ export const db = orchidORM({}, {
107
+ some: Some
108
+ });
109
+ `);
110
+
111
+ await updateMainFile(mainFilePath, tablePath, ast.addTable);
112
+
113
+ expect(fs.writeFile).toBeCalledWith(
114
+ mainFilePath,
115
+ `
116
+ import { orchidORM } from 'orchid-orm';
117
+ import { Some } from './tables/some';
118
+ import { Table } from './tables/table';
119
+
120
+ export const db = orchidORM({}, {
121
+ some: Some,
122
+ table: Table,
123
+ });
124
+ `,
125
+ );
126
+ });
127
+ });
128
+
129
+ describe('drop table', () => {
130
+ it('should remove table', async () => {
131
+ asMock(fs.readFile).mockResolvedValue(`
132
+ import { orchidORM } from 'orchid-orm';
133
+ import { Table } from './tables/table';
134
+
135
+ export const db = orchidORM({}, {
136
+ table: Table,
137
+ });
138
+ `);
139
+
140
+ await updateMainFile(mainFilePath, tablePath, ast.dropTable);
141
+
142
+ expect(fs.writeFile).toBeCalledWith(
143
+ mainFilePath,
144
+ `
145
+ import { orchidORM } from 'orchid-orm';
146
+
147
+ export const db = orchidORM({}, {
148
+ });
149
+ `,
150
+ );
151
+ });
152
+
153
+ it('should remove aliased import', async () => {
154
+ asMock(fs.readFile).mockResolvedValue(`
155
+ import { orchidORM } from 'orchid-orm';
156
+ import { Table as koko } from './tables/table';
157
+
158
+ export const db = orchidORM({}, {
159
+ koko: koko,
160
+ });
161
+ `);
162
+
163
+ await updateMainFile(mainFilePath, tablePath, ast.dropTable);
164
+
165
+ expect(fs.writeFile).toBeCalledWith(
166
+ mainFilePath,
167
+ `
168
+ import { orchidORM } from 'orchid-orm';
169
+
170
+ export const db = orchidORM({}, {
171
+ });
172
+ `,
173
+ );
174
+ });
175
+
176
+ it('should remove short form of key and value', async () => {
177
+ asMock(fs.readFile).mockResolvedValue(`
178
+ import { orchidORM } from 'orchid-orm';
179
+ import { Table as koko } from './tables/table';
180
+
181
+ export const db = orchidORM({}, {
182
+ koko,
183
+ });
184
+ `);
185
+
186
+ await updateMainFile(mainFilePath, tablePath, ast.dropTable);
187
+
188
+ expect(fs.writeFile).toBeCalledWith(
189
+ mainFilePath,
190
+ `
191
+ import { orchidORM } from 'orchid-orm';
192
+
193
+ export const db = orchidORM({}, {
194
+ });
195
+ `,
196
+ );
197
+ });
198
+
199
+ it('should not remove other tables', async () => {
200
+ asMock(fs.readFile).mockResolvedValue(`
201
+ import { orchidORM } from 'orchid-orm';
202
+ import { One } from './tables/one';
203
+ import { Table } from './tables/table';
204
+ import { Two } from './tables/two';
205
+
206
+ export const db = orchidORM({}, {
207
+ one,
208
+ table: Table,
209
+ two,
210
+ });
211
+ `);
212
+
213
+ await updateMainFile(mainFilePath, tablePath, ast.dropTable);
214
+
215
+ expect(fs.writeFile).toBeCalledWith(
216
+ mainFilePath,
217
+ `
218
+ import { orchidORM } from 'orchid-orm';
219
+ import { One } from './tables/one';
220
+ import { Two } from './tables/two';
221
+
222
+ export const db = orchidORM({}, {
223
+ one,
224
+ two,
225
+ });
226
+ `,
227
+ );
228
+ });
229
+ });
230
+ });
@@ -0,0 +1,163 @@
1
+ import { RakeDbAst } from 'rake-db';
2
+ import fs from 'fs/promises';
3
+ import {
4
+ createSourceFile,
5
+ NodeArray,
6
+ ObjectLiteralExpression,
7
+ ScriptTarget,
8
+ Statement,
9
+ } from 'typescript';
10
+ import { toCamelCase, toPascalCase } from '../utils';
11
+ import { AppCodeUpdaterError } from './appCodeUpdater';
12
+ import { FileChanges } from './fileChanges';
13
+ import { ts } from './tsUtils';
14
+
15
+ type Context = {
16
+ path: string;
17
+ tablePath: (name: string) => string;
18
+ statements: NodeArray<Statement>;
19
+ object: ObjectLiteralExpression;
20
+ content: string;
21
+ spaces: string;
22
+ };
23
+
24
+ const libraryName = 'orchid-orm';
25
+ const importKey = 'orchidORM';
26
+
27
+ export const updateMainFile = async (
28
+ path: string,
29
+ tablePath: (name: string) => string,
30
+ ast: RakeDbAst,
31
+ ) => {
32
+ const content = await fs.readFile(path, 'utf-8');
33
+
34
+ const { statements } = createSourceFile(
35
+ 'file.ts',
36
+ content,
37
+ ScriptTarget.Latest,
38
+ true,
39
+ );
40
+
41
+ const importName = ts.import.getStatementsImportedName(
42
+ statements,
43
+ libraryName,
44
+ importKey,
45
+ );
46
+ if (!importName) {
47
+ throw new AppCodeUpdaterError(
48
+ `Main file does not contain import of orchid-orm`,
49
+ );
50
+ }
51
+
52
+ const object = getTablesListObject(importName, statements);
53
+ if (!object) {
54
+ throw new Error('List of tables is not found in main file');
55
+ }
56
+
57
+ const spaces = ts.spaces.getAtLine(content, object.end);
58
+
59
+ const context: Context = {
60
+ path,
61
+ tablePath,
62
+ statements,
63
+ object,
64
+ content,
65
+ spaces,
66
+ };
67
+
68
+ if (ast.type === 'table') {
69
+ if (ast.action === 'create') {
70
+ return fs.writeFile(path, createTable(context, ast));
71
+ } else {
72
+ return fs.writeFile(path, dropTable(context, ast));
73
+ }
74
+ }
75
+
76
+ // rename table is not handled because renaming of the class and the file is better to be done by the editor,
77
+ // editor can scan all project files, rename import path and imported class name
78
+ };
79
+
80
+ const createTable = (
81
+ { path, tablePath, statements, object, content, spaces }: Context,
82
+ ast: RakeDbAst.Table,
83
+ ) => {
84
+ const key = toCamelCase(ast.name);
85
+ const value = toPascalCase(ast.name);
86
+
87
+ const changes = new FileChanges(content);
88
+
89
+ const importPath = ts.path.getRelative(path, tablePath(ast.name));
90
+ const importPos = ts.import.getEndPos(statements);
91
+ changes.add(
92
+ importPos,
93
+ `${importPos === 0 ? '' : '\n'}import { ${value} } from '${importPath}';`,
94
+ );
95
+
96
+ let insert = `\n${spaces} ${key}: ${value},`;
97
+ if (object.properties.length && !object.properties.hasTrailingComma) {
98
+ insert = `,${insert}`;
99
+ }
100
+ if (!content.slice(object.properties.end, object.end).includes('\n')) {
101
+ insert += `\n${spaces}`;
102
+ }
103
+ changes.add(object.properties.end, insert);
104
+
105
+ return changes.apply();
106
+ };
107
+
108
+ const dropTable = (
109
+ { path, tablePath, statements, object, content }: Context,
110
+ ast: RakeDbAst.Table,
111
+ ) => {
112
+ const changes = new FileChanges(content);
113
+
114
+ const importPath = ts.path.getRelative(path, tablePath(ast.name));
115
+ const tableClassName = toPascalCase(ast.name);
116
+ const importNames: string[] = [];
117
+ for (const node of ts.import.iterateWithSource(statements, importPath)) {
118
+ changes.remove(node.pos, node.end);
119
+
120
+ const name = ts.import.getImportName(node, tableClassName);
121
+ if (name && !importNames.includes(name)) {
122
+ importNames.push(name);
123
+ }
124
+ }
125
+
126
+ for (const prop of object.properties) {
127
+ const name = ts.prop.getValue(prop);
128
+ if (!name || !importNames.includes(name)) continue;
129
+
130
+ let { end } = prop;
131
+ if (content[end] === ',') end++;
132
+ changes.remove(prop.pos, end);
133
+ }
134
+
135
+ return changes.apply();
136
+ };
137
+
138
+ const getTablesListObject = (
139
+ importName: string,
140
+ statements: NodeArray<Statement>,
141
+ ): ObjectLiteralExpression | undefined => {
142
+ for (const node of ts.variable.iterateDeclarations(statements)) {
143
+ const call = node.initializer;
144
+ if (!ts.is.call(call)) continue;
145
+
146
+ if (call.expression.getText() !== importName) continue;
147
+
148
+ if (call.arguments.length !== 2) {
149
+ throw new Error(
150
+ 'Invalid number of arguments when initializing orchid orm',
151
+ );
152
+ }
153
+
154
+ const object = call.arguments[1];
155
+ if (!ts.is.objectLiteral(object)) {
156
+ throw new Error('Second argument of orchidORM must be an object literal');
157
+ }
158
+
159
+ return object;
160
+ }
161
+
162
+ return;
163
+ };
@@ -0,0 +1,19 @@
1
+ // import { RakeDbAst } from 'rake-db';
2
+ //
3
+ // export const updateTableFile = async (
4
+ // tablePath: (name: string) => string,
5
+ // ast: RakeDbAst,
6
+ // ) => {
7
+ // if (ast.type === 'table') {
8
+ // if (ast.action === 'create') {
9
+ // createTable(tablePath, ast);
10
+ // }
11
+ // }
12
+ // };
13
+ //
14
+ // const createTable = (
15
+ // tablePath: (name: string) => string,
16
+ // ast: RakeDbAst.Table,
17
+ // ) => {
18
+ //
19
+ // };
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
- export * from './model';
1
+ export * from './table';
2
2
  export * from './orm';
3
3
  export * from './repo';
4
+ export type {
5
+ appCodeUpdater,
6
+ AppCodeUpdaterConfig,
7
+ } from './appCodeUpdater/appCodeUpdater';
package/src/orm.test.ts CHANGED
@@ -6,21 +6,21 @@ import {
6
6
  useTestDatabase,
7
7
  } from './test-utils/test-utils';
8
8
  import { pgConfig } from './test-utils/test-db';
9
- import { createModel } from './model';
9
+ import { createBaseTable } from './table';
10
10
  import { columnTypes } from 'pqb';
11
11
 
12
12
  describe('orm', () => {
13
13
  useTestDatabase();
14
14
 
15
- const Model = createModel({
15
+ const BaseTable = createBaseTable({
16
16
  columnTypes: {
17
17
  ...columnTypes,
18
18
  text: (min = 0, max = Infinity) => columnTypes.text(min, max),
19
19
  },
20
20
  });
21
21
 
22
- type User = UserModel['columns']['type'];
23
- class UserModel extends Model {
22
+ type User = UserTable['columns']['type'];
23
+ class UserTable extends BaseTable {
24
24
  table = 'user';
25
25
  columns = this.setColumns((t) => ({
26
26
  id: t.serial().primaryKey(),
@@ -29,17 +29,17 @@ describe('orm', () => {
29
29
  }));
30
30
  }
31
31
 
32
- class ProfileModel extends Model {
32
+ class ProfileTable extends BaseTable {
33
33
  table = 'profile';
34
34
  columns = this.setColumns((t) => ({
35
35
  id: t.serial().primaryKey(),
36
36
  }));
37
37
  }
38
38
 
39
- it('should return object with provided adapter, close and transaction method, models', () => {
39
+ it('should return object with provided adapter, close and transaction method, tables', () => {
40
40
  const db = orchidORM(pgConfig, {
41
- user: UserModel,
42
- profile: ProfileModel,
41
+ user: UserTable,
42
+ profile: ProfileTable,
43
43
  });
44
44
 
45
45
  expect('$adapter' in db).toBe(true);
@@ -50,10 +50,10 @@ describe('orm', () => {
50
50
  );
51
51
  });
52
52
 
53
- it('should return model which is a queryable interface', async () => {
53
+ it('should return table which is a queryable interface', async () => {
54
54
  const db = orchidORM(pgConfig, {
55
- user: UserModel,
56
- profile: ProfileModel,
55
+ user: UserTable,
56
+ profile: ProfileTable,
57
57
  });
58
58
 
59
59
  const { id, name } = await db.user.create(userData);
@@ -80,8 +80,8 @@ describe('orm', () => {
80
80
  const db = orchidORM(
81
81
  { ...pgConfig, autoPreparedStatements: true },
82
82
  {
83
- user: UserModel,
84
- profile: ProfileModel,
83
+ user: UserTable,
84
+ profile: ProfileTable,
85
85
  },
86
86
  );
87
87