orchid-orm 1.4.16 → 1.4.19

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.
@@ -0,0 +1,22 @@
1
+ import { RakeDbAst } from 'rake-db';
2
+ import { createTable } from './createTable';
3
+ import { changeTable } from './changeTable';
4
+ import { renameTable } from './renameTable';
5
+
6
+ export type UpdateTableFileParams = {
7
+ baseTablePath: string;
8
+ baseTableName: string;
9
+ tablePath: (name: string) => string;
10
+ ast: RakeDbAst;
11
+ };
12
+
13
+ export const updateTableFile = async (params: UpdateTableFileParams) => {
14
+ const { ast } = params;
15
+ if (ast.type === 'table' && ast.action === 'create') {
16
+ await createTable({ ...params, ast });
17
+ } else if (ast.type === 'changeTable') {
18
+ await changeTable({ ...params, ast });
19
+ } else if (ast.type === 'renameTable') {
20
+ await renameTable({ ...params, ast });
21
+ }
22
+ };
@@ -0,0 +1,10 @@
1
+ import path from 'path';
2
+
3
+ export const getRelativePath = (from: string, to: string) => {
4
+ const rel = path.relative(path.dirname(from), to);
5
+ return rel.startsWith('./') || rel.startsWith('../') ? rel : `./${rel}`;
6
+ };
7
+
8
+ export const getImportPath = (from: string, to: string) => {
9
+ return getRelativePath(from, to).replace(/\.[tj]s$/, '');
10
+ };
package/src/table.test.ts CHANGED
@@ -13,6 +13,9 @@ describe('table', () => {
13
13
  class Type extends ColumnType {
14
14
  dataType = 'type';
15
15
  operators = Operators.any;
16
+ toCode() {
17
+ return '';
18
+ }
16
19
  }
17
20
  const type = new Type();
18
21
  const BaseTable = createBaseTable({ columnTypes: { type: () => type } });
@@ -1,19 +0,0 @@
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
- // };