@omnigraph/sql 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/directives.js +59 -0
- package/dist/cjs/directives.js.map +7 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/introspect/mysql.js +93 -0
- package/dist/cjs/introspect/postgres.js +106 -0
- package/dist/cjs/introspect/sqlite.js +60 -0
- package/dist/cjs/introspect/sqlite.js.map +7 -0
- package/dist/cjs/introspect/types.js +0 -0
- package/dist/cjs/introspect/types.js.map +7 -0
- package/dist/cjs/naming.js +54 -0
- package/dist/cjs/naming.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/schema.js +712 -0
- package/dist/cjs/schema.js.map +7 -0
- package/dist/cjs/type-map.js +40 -0
- package/dist/cjs/type-map.js.map +7 -0
- package/dist/esm/directives.js +55 -0
- package/dist/esm/directives.js.map +7 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/introspect/mysql.js +90 -0
- package/dist/esm/introspect/postgres.js +102 -0
- package/dist/esm/introspect/sqlite.js +57 -0
- package/dist/esm/introspect/sqlite.js.map +7 -0
- package/dist/esm/introspect/types.js +0 -0
- package/dist/esm/introspect/types.js.map +7 -0
- package/dist/esm/naming.js +50 -0
- package/dist/esm/naming.js.map +7 -0
- package/dist/esm/schema.js +707 -0
- package/dist/esm/schema.js.map +7 -0
- package/dist/esm/type-map.js +37 -0
- package/dist/esm/type-map.js.map +7 -0
- package/dist/package.json +54 -0
- package/dist/typings/directives.d.cts +17 -0
- package/dist/typings/directives.d.ts +17 -0
- package/dist/typings/index.d.cts +10 -0
- package/dist/typings/index.d.ts +10 -0
- package/dist/typings/introspect/mysql.d.cts +7 -0
- package/dist/typings/introspect/mysql.d.ts +7 -0
- package/dist/typings/introspect/postgres.d.cts +9 -0
- package/dist/typings/introspect/postgres.d.ts +9 -0
- package/dist/typings/introspect/sqlite.d.cts +8 -0
- package/dist/typings/introspect/sqlite.d.ts +8 -0
- package/dist/typings/introspect/types.d.cts +26 -0
- package/dist/typings/introspect/types.d.ts +26 -0
- package/dist/typings/naming.d.cts +17 -0
- package/dist/typings/naming.d.ts +17 -0
- package/dist/typings/schema.d.cts +39 -0
- package/dist/typings/schema.d.ts +39 -0
- package/dist/typings/type-map.d.cts +4 -0
- package/dist/typings/type-map.d.ts +4 -0
- package/package.json +61 -4
- package/src/directives.ts +67 -0
- package/src/index.ts +20 -0
- package/src/introspect/mysql.ts +110 -0
- package/src/introspect/postgres.ts +142 -0
- package/src/introspect/sqlite.ts +90 -0
- package/src/introspect/types.ts +31 -0
- package/src/naming.ts +67 -0
- package/src/schema.ts +834 -0
- package/src/type-map.ts +50 -0
- package/test/__snapshots__/sqlite-chinook.spec.ts.snap +328 -0
- package/test/sqlite-chinook.spec.ts +33 -0
- package/README.md +0 -3
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createPool, type RowDataPacket } from 'mysql2/promise';
|
|
2
|
+
import { parseSqlUri } from '@graphql-mesh/transport-sql';
|
|
3
|
+
import type { SqlColumnMeta, SqlForeignKeyMeta, SqlSchemaMeta, SqlTableMeta } from './types.js';
|
|
4
|
+
|
|
5
|
+
export interface IntrospectMysqlOpts {
|
|
6
|
+
connectionString: string;
|
|
7
|
+
includeTables?: string[];
|
|
8
|
+
excludeTables?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function introspectMysql(opts: IntrospectMysqlOpts): Promise<SqlSchemaMeta> {
|
|
12
|
+
const parsed = parseSqlUri(opts.connectionString);
|
|
13
|
+
if (parsed.adapter !== 'mysql' || !parsed.database) {
|
|
14
|
+
throw new Error('MySQL introspection requires a mysql://…/database URI');
|
|
15
|
+
}
|
|
16
|
+
const pool = createPool({
|
|
17
|
+
host: parsed.host,
|
|
18
|
+
port: parsed.port,
|
|
19
|
+
user: parsed.user,
|
|
20
|
+
password: parsed.password,
|
|
21
|
+
database: parsed.database,
|
|
22
|
+
ssl: parsed.ssl ? { rejectUnauthorized: false } : undefined,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
const database = parsed.database;
|
|
26
|
+
const [tableRows] = await pool.query<RowDataPacket[]>(
|
|
27
|
+
`SELECT TABLE_NAME AS name
|
|
28
|
+
FROM information_schema.TABLES
|
|
29
|
+
WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'
|
|
30
|
+
ORDER BY TABLE_NAME`,
|
|
31
|
+
[database],
|
|
32
|
+
);
|
|
33
|
+
let tableNames = tableRows.map(r => String(r.name));
|
|
34
|
+
if (opts.includeTables?.length) {
|
|
35
|
+
const allow = new Set(opts.includeTables);
|
|
36
|
+
tableNames = tableNames.filter(n => allow.has(n));
|
|
37
|
+
}
|
|
38
|
+
if (opts.excludeTables?.length) {
|
|
39
|
+
const deny = new Set(opts.excludeTables);
|
|
40
|
+
tableNames = tableNames.filter(n => !deny.has(n));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tables: SqlTableMeta[] = [];
|
|
44
|
+
for (const name of tableNames) {
|
|
45
|
+
const [colRows] = await pool.query<RowDataPacket[]>(
|
|
46
|
+
`SELECT
|
|
47
|
+
COLUMN_NAME AS name,
|
|
48
|
+
DATA_TYPE AS dataType,
|
|
49
|
+
COLUMN_TYPE AS columnType,
|
|
50
|
+
IS_NULLABLE AS isNullable,
|
|
51
|
+
COLUMN_KEY AS columnKey,
|
|
52
|
+
EXTRA AS extra
|
|
53
|
+
FROM information_schema.COLUMNS
|
|
54
|
+
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?
|
|
55
|
+
ORDER BY ORDINAL_POSITION`,
|
|
56
|
+
[database, name],
|
|
57
|
+
);
|
|
58
|
+
const columns: SqlColumnMeta[] = colRows.map(c => ({
|
|
59
|
+
name: String(c.name),
|
|
60
|
+
dataType: String(c.columnType || c.dataType || 'TEXT'),
|
|
61
|
+
notNull: String(c.isNullable).toUpperCase() === 'NO',
|
|
62
|
+
primaryKey: String(c.columnKey).toUpperCase() === 'PRI',
|
|
63
|
+
autoIncrement: String(c.extra || '')
|
|
64
|
+
.toLowerCase()
|
|
65
|
+
.includes('auto_increment'),
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
const [fkRows] = await pool.query<RowDataPacket[]>(
|
|
69
|
+
`SELECT
|
|
70
|
+
CONSTRAINT_NAME AS constraintName,
|
|
71
|
+
COLUMN_NAME AS columnName,
|
|
72
|
+
REFERENCED_TABLE_NAME AS refTable,
|
|
73
|
+
REFERENCED_COLUMN_NAME AS refColumn,
|
|
74
|
+
ORDINAL_POSITION AS seq
|
|
75
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
76
|
+
WHERE TABLE_SCHEMA = ?
|
|
77
|
+
AND TABLE_NAME = ?
|
|
78
|
+
AND REFERENCED_TABLE_NAME IS NOT NULL
|
|
79
|
+
ORDER BY CONSTRAINT_NAME, ORDINAL_POSITION`,
|
|
80
|
+
[database, name],
|
|
81
|
+
);
|
|
82
|
+
const fkByName = new Map<string, SqlForeignKeyMeta>();
|
|
83
|
+
for (const fk of fkRows) {
|
|
84
|
+
const constraintName = String(fk.constraintName);
|
|
85
|
+
let meta = fkByName.get(constraintName);
|
|
86
|
+
if (!meta) {
|
|
87
|
+
meta = {
|
|
88
|
+
columns: [],
|
|
89
|
+
refTable: String(fk.refTable),
|
|
90
|
+
refColumns: [],
|
|
91
|
+
};
|
|
92
|
+
fkByName.set(constraintName, meta);
|
|
93
|
+
}
|
|
94
|
+
const idx = Number(fk.seq) - 1;
|
|
95
|
+
meta.columns[idx] = String(fk.columnName);
|
|
96
|
+
meta.refColumns[idx] = String(fk.refColumn);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
tables.push({
|
|
100
|
+
name,
|
|
101
|
+
columns,
|
|
102
|
+
foreignKeys: [...fkByName.values()],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { adapter: 'mysql', tables };
|
|
107
|
+
} finally {
|
|
108
|
+
await pool.end();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import pg from 'pg';
|
|
2
|
+
import { parseSqlUri } from '@graphql-mesh/transport-sql';
|
|
3
|
+
import type { SqlColumnMeta, SqlForeignKeyMeta, SqlSchemaMeta, SqlTableMeta } from './types.js';
|
|
4
|
+
|
|
5
|
+
export interface IntrospectPostgresOpts {
|
|
6
|
+
connectionString: string;
|
|
7
|
+
includeTables?: string[];
|
|
8
|
+
excludeTables?: string[];
|
|
9
|
+
/** Defaults to `public` */
|
|
10
|
+
schema?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function introspectPostgres(opts: IntrospectPostgresOpts): Promise<SqlSchemaMeta> {
|
|
14
|
+
const parsed = parseSqlUri(opts.connectionString);
|
|
15
|
+
if (parsed.adapter !== 'postgres') {
|
|
16
|
+
throw new Error('Postgres introspection requires a postgres(ql)://… URI');
|
|
17
|
+
}
|
|
18
|
+
const schemaName = opts.schema || 'public';
|
|
19
|
+
const pool = new pg.Pool({
|
|
20
|
+
connectionString: opts.connectionString,
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
const tableRes = await pool.query<{ name: string }>(
|
|
24
|
+
`SELECT table_name AS name
|
|
25
|
+
FROM information_schema.tables
|
|
26
|
+
WHERE table_schema = $1 AND table_type = 'BASE TABLE'
|
|
27
|
+
ORDER BY table_name`,
|
|
28
|
+
[schemaName],
|
|
29
|
+
);
|
|
30
|
+
let tableNames = tableRes.rows.map(r => String(r.name));
|
|
31
|
+
if (opts.includeTables?.length) {
|
|
32
|
+
const allow = new Set(opts.includeTables);
|
|
33
|
+
tableNames = tableNames.filter(n => allow.has(n));
|
|
34
|
+
}
|
|
35
|
+
if (opts.excludeTables?.length) {
|
|
36
|
+
const deny = new Set(opts.excludeTables);
|
|
37
|
+
tableNames = tableNames.filter(n => !deny.has(n));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const tables: SqlTableMeta[] = [];
|
|
41
|
+
for (const name of tableNames) {
|
|
42
|
+
const colRes = await pool.query<{
|
|
43
|
+
name: string;
|
|
44
|
+
data_type: string;
|
|
45
|
+
udt_name: string;
|
|
46
|
+
is_nullable: string;
|
|
47
|
+
column_default: string | null;
|
|
48
|
+
}>(
|
|
49
|
+
`SELECT
|
|
50
|
+
column_name AS name,
|
|
51
|
+
data_type,
|
|
52
|
+
udt_name,
|
|
53
|
+
is_nullable,
|
|
54
|
+
column_default
|
|
55
|
+
FROM information_schema.columns
|
|
56
|
+
WHERE table_schema = $1 AND table_name = $2
|
|
57
|
+
ORDER BY ordinal_position`,
|
|
58
|
+
[schemaName, name],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const pkRes = await pool.query<{ column_name: string }>(
|
|
62
|
+
`SELECT kcu.column_name
|
|
63
|
+
FROM information_schema.table_constraints tc
|
|
64
|
+
JOIN information_schema.key_column_usage kcu
|
|
65
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
66
|
+
AND tc.table_schema = kcu.table_schema
|
|
67
|
+
WHERE tc.table_schema = $1
|
|
68
|
+
AND tc.table_name = $2
|
|
69
|
+
AND tc.constraint_type = 'PRIMARY KEY'
|
|
70
|
+
ORDER BY kcu.ordinal_position`,
|
|
71
|
+
[schemaName, name],
|
|
72
|
+
);
|
|
73
|
+
const pkCols = new Set(pkRes.rows.map(r => String(r.column_name)));
|
|
74
|
+
|
|
75
|
+
const columns: SqlColumnMeta[] = colRes.rows.map(c => {
|
|
76
|
+
const dataType = String(c.udt_name || c.data_type || 'text');
|
|
77
|
+
const def = c.column_default != null ? String(c.column_default) : '';
|
|
78
|
+
return {
|
|
79
|
+
name: String(c.name),
|
|
80
|
+
dataType,
|
|
81
|
+
notNull: String(c.is_nullable).toUpperCase() === 'NO',
|
|
82
|
+
primaryKey: pkCols.has(String(c.name)),
|
|
83
|
+
autoIncrement: /nextval\(/i.test(def) || /identity/i.test(def),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const fkRes = await pool.query<{
|
|
88
|
+
constraint_name: string;
|
|
89
|
+
column_name: string;
|
|
90
|
+
foreign_table_name: string;
|
|
91
|
+
foreign_column_name: string;
|
|
92
|
+
ordinal_position: number;
|
|
93
|
+
}>(
|
|
94
|
+
`SELECT
|
|
95
|
+
tc.constraint_name,
|
|
96
|
+
kcu.column_name,
|
|
97
|
+
ccu.table_name AS foreign_table_name,
|
|
98
|
+
ccu.column_name AS foreign_column_name,
|
|
99
|
+
kcu.ordinal_position
|
|
100
|
+
FROM information_schema.table_constraints AS tc
|
|
101
|
+
JOIN information_schema.key_column_usage AS kcu
|
|
102
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
103
|
+
AND tc.table_schema = kcu.table_schema
|
|
104
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
|
105
|
+
ON ccu.constraint_name = tc.constraint_name
|
|
106
|
+
AND ccu.table_schema = tc.table_schema
|
|
107
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
108
|
+
AND tc.table_schema = $1
|
|
109
|
+
AND tc.table_name = $2
|
|
110
|
+
ORDER BY tc.constraint_name, kcu.ordinal_position`,
|
|
111
|
+
[schemaName, name],
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const fkByName = new Map<string, SqlForeignKeyMeta>();
|
|
115
|
+
for (const fk of fkRes.rows) {
|
|
116
|
+
const constraintName = String(fk.constraint_name);
|
|
117
|
+
let meta = fkByName.get(constraintName);
|
|
118
|
+
if (!meta) {
|
|
119
|
+
meta = {
|
|
120
|
+
columns: [],
|
|
121
|
+
refTable: String(fk.foreign_table_name),
|
|
122
|
+
refColumns: [],
|
|
123
|
+
};
|
|
124
|
+
fkByName.set(constraintName, meta);
|
|
125
|
+
}
|
|
126
|
+
const idx = Number(fk.ordinal_position) - 1;
|
|
127
|
+
meta.columns[idx] = String(fk.column_name);
|
|
128
|
+
meta.refColumns[idx] = String(fk.foreign_column_name);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
tables.push({
|
|
132
|
+
name,
|
|
133
|
+
columns,
|
|
134
|
+
foreignKeys: [...fkByName.values()],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return { adapter: 'postgres', tables };
|
|
139
|
+
} finally {
|
|
140
|
+
await pool.end();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { resolveSqlitePath } from '@graphql-mesh/transport-sql';
|
|
3
|
+
import type { SqlColumnMeta, SqlForeignKeyMeta, SqlSchemaMeta, SqlTableMeta } from './types.js';
|
|
4
|
+
|
|
5
|
+
export interface IntrospectSqliteOpts {
|
|
6
|
+
db: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
includeTables?: string[];
|
|
9
|
+
excludeTables?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function introspectSqlite(opts: IntrospectSqliteOpts): SqlSchemaMeta {
|
|
13
|
+
const dbPath = resolveSqlitePath(
|
|
14
|
+
opts.db.startsWith('file:') ? opts.db : `file:${opts.db}`,
|
|
15
|
+
opts.cwd,
|
|
16
|
+
);
|
|
17
|
+
const db = new DatabaseSync(dbPath);
|
|
18
|
+
try {
|
|
19
|
+
const tableRows = db
|
|
20
|
+
.prepare(
|
|
21
|
+
`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name`,
|
|
22
|
+
)
|
|
23
|
+
.all() as { name: string }[];
|
|
24
|
+
|
|
25
|
+
let tableNames = tableRows.map(r => r.name);
|
|
26
|
+
if (opts.includeTables?.length) {
|
|
27
|
+
const allow = new Set(opts.includeTables);
|
|
28
|
+
tableNames = tableNames.filter(n => allow.has(n));
|
|
29
|
+
}
|
|
30
|
+
if (opts.excludeTables?.length) {
|
|
31
|
+
const deny = new Set(opts.excludeTables);
|
|
32
|
+
tableNames = tableNames.filter(n => !deny.has(n));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const tables: SqlTableMeta[] = tableNames.map(name => {
|
|
36
|
+
const cols = db.prepare(`PRAGMA table_info(${quote(name)})`).all() as {
|
|
37
|
+
cid: number;
|
|
38
|
+
name: string;
|
|
39
|
+
type: string;
|
|
40
|
+
notnull: number;
|
|
41
|
+
dflt_value: unknown;
|
|
42
|
+
pk: number;
|
|
43
|
+
}[];
|
|
44
|
+
const columns: SqlColumnMeta[] = cols.map(c => ({
|
|
45
|
+
name: c.name,
|
|
46
|
+
dataType: c.type || 'TEXT',
|
|
47
|
+
notNull: Boolean(c.notnull) || Boolean(c.pk),
|
|
48
|
+
primaryKey: Boolean(c.pk),
|
|
49
|
+
autoIncrement: false,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const solePk = columns.filter(c => c.primaryKey);
|
|
53
|
+
if (solePk.length === 1 && /int/i.test(solePk[0].dataType)) {
|
|
54
|
+
solePk[0].autoIncrement = true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const fkRows = db.prepare(`PRAGMA foreign_key_list(${quote(name)})`).all() as {
|
|
58
|
+
id: number;
|
|
59
|
+
seq: number;
|
|
60
|
+
table: string;
|
|
61
|
+
from: string;
|
|
62
|
+
to: string;
|
|
63
|
+
}[];
|
|
64
|
+
const fkById = new Map<number, SqlForeignKeyMeta>();
|
|
65
|
+
for (const fk of fkRows) {
|
|
66
|
+
let meta = fkById.get(fk.id);
|
|
67
|
+
if (!meta) {
|
|
68
|
+
meta = { columns: [], refTable: fk.table, refColumns: [] };
|
|
69
|
+
fkById.set(fk.id, meta);
|
|
70
|
+
}
|
|
71
|
+
meta.columns[fk.seq] = fk.from;
|
|
72
|
+
meta.refColumns[fk.seq] = fk.to;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
name,
|
|
77
|
+
columns,
|
|
78
|
+
foreignKeys: [...fkById.values()],
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return { adapter: 'sqlite', tables };
|
|
83
|
+
} finally {
|
|
84
|
+
db.close();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function quote(name: string): string {
|
|
89
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
90
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SqlAdapter } from '@graphql-mesh/transport-sql';
|
|
2
|
+
|
|
3
|
+
export type { SqlAdapter };
|
|
4
|
+
|
|
5
|
+
export interface SqlColumnMeta {
|
|
6
|
+
name: string;
|
|
7
|
+
dataType: string;
|
|
8
|
+
notNull: boolean;
|
|
9
|
+
primaryKey: boolean;
|
|
10
|
+
autoIncrement?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SqlForeignKeyMeta {
|
|
14
|
+
/** Local table column(s) */
|
|
15
|
+
columns: string[];
|
|
16
|
+
/** Referenced table */
|
|
17
|
+
refTable: string;
|
|
18
|
+
/** Referenced column(s) */
|
|
19
|
+
refColumns: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SqlTableMeta {
|
|
23
|
+
name: string;
|
|
24
|
+
columns: SqlColumnMeta[];
|
|
25
|
+
foreignKeys: SqlForeignKeyMeta[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SqlSchemaMeta {
|
|
29
|
+
adapter: SqlAdapter;
|
|
30
|
+
tables: SqlTableMeta[];
|
|
31
|
+
}
|
package/src/naming.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { camelCase, constantCase, pascalCase } from 'change-case';
|
|
2
|
+
import pluralize from 'pluralize';
|
|
3
|
+
|
|
4
|
+
export interface SqlNaming {
|
|
5
|
+
typeName(table: string): string;
|
|
6
|
+
fieldName(column: string): string;
|
|
7
|
+
pluralField(typeName: string): string;
|
|
8
|
+
singularField(typeName: string): string;
|
|
9
|
+
connectionField(typeName: string): string;
|
|
10
|
+
countField(typeName: string): string;
|
|
11
|
+
orderByEnum(typeName: string): string;
|
|
12
|
+
filterInput(typeName: string): string;
|
|
13
|
+
createInput(typeName: string): string;
|
|
14
|
+
updateInput(typeName: string): string;
|
|
15
|
+
payloadType(typeName: string): string;
|
|
16
|
+
deletePayloadType(typeName: string): string;
|
|
17
|
+
orderValue(fieldName: string, dir: 'ASC' | 'DESC'): string;
|
|
18
|
+
pkFieldName(column: string, isSolePk: boolean): string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createDefaultNaming(): SqlNaming {
|
|
22
|
+
return {
|
|
23
|
+
typeName(table) {
|
|
24
|
+
return pascalCase(pluralize.singular(table));
|
|
25
|
+
},
|
|
26
|
+
fieldName(column) {
|
|
27
|
+
return camelCase(column);
|
|
28
|
+
},
|
|
29
|
+
pluralField(typeName) {
|
|
30
|
+
return camelCase(pluralize.plural(typeName));
|
|
31
|
+
},
|
|
32
|
+
singularField(typeName) {
|
|
33
|
+
return camelCase(typeName);
|
|
34
|
+
},
|
|
35
|
+
connectionField(typeName) {
|
|
36
|
+
return `all${pascalCase(pluralize.plural(typeName))}`;
|
|
37
|
+
},
|
|
38
|
+
countField(typeName) {
|
|
39
|
+
return `${camelCase(pluralize.plural(typeName))}Count`;
|
|
40
|
+
},
|
|
41
|
+
orderByEnum(typeName) {
|
|
42
|
+
return `${typeName}OrderBy`;
|
|
43
|
+
},
|
|
44
|
+
filterInput(typeName) {
|
|
45
|
+
return `${typeName}Filter`;
|
|
46
|
+
},
|
|
47
|
+
createInput(typeName) {
|
|
48
|
+
return `Create${typeName}Input`;
|
|
49
|
+
},
|
|
50
|
+
updateInput(typeName) {
|
|
51
|
+
return `Update${typeName}Input`;
|
|
52
|
+
},
|
|
53
|
+
payloadType(typeName) {
|
|
54
|
+
return `${typeName}Payload`;
|
|
55
|
+
},
|
|
56
|
+
deletePayloadType(typeName) {
|
|
57
|
+
return `Delete${typeName}Payload`;
|
|
58
|
+
},
|
|
59
|
+
orderValue(fieldName, dir) {
|
|
60
|
+
return `${constantCase(fieldName)}_${dir}`;
|
|
61
|
+
},
|
|
62
|
+
pkFieldName(column, isSolePk) {
|
|
63
|
+
if (isSolePk) return 'id';
|
|
64
|
+
return camelCase(column);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|