Skip to content

Commit 790038f

Browse files
Copilothuangyiirene
andcommitted
Fix type mapping: use correct FieldType values (number, object)
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 765adca commit 790038f

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

packages/tools/cli/USAGE_EXAMPLES.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,16 @@ The sync command automatically maps SQL types to ObjectQL field types:
624624
625625
| SQL Type | ObjectQL Type |
626626
|----------|---------------|
627-
| INT, INTEGER, BIGINT | integer |
627+
| INT, INTEGER, BIGINT, SERIAL | number |
628628
| FLOAT, DOUBLE, DECIMAL, NUMERIC | number |
629629
| BOOLEAN, BIT | boolean |
630-
| VARCHAR, CHAR, TEXT | text |
631-
| TEXT, CLOB | textarea |
630+
| VARCHAR, CHAR | text |
631+
| TEXT, CLOB, LONGTEXT | textarea |
632632
| TIMESTAMP, DATETIME | datetime |
633633
| DATE | date |
634634
| TIME | time |
635-
| JSON, JSONB | json |
635+
| JSON, JSONB | object |
636+
| BLOB, BINARY, BYTEA | file |
636637
637638
**Foreign Key Detection:**
638639

packages/tools/cli/src/commands/sync.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import chalk from 'chalk';
44
import * as yaml from 'js-yaml';
5-
import { IntrospectedSchema, IntrospectedTable, IntrospectedColumn, ObjectConfig, IObjectQL, FieldConfig } from '@objectql/types';
5+
import { IntrospectedSchema, IntrospectedTable, IntrospectedColumn, ObjectConfig, IObjectQL, FieldConfig, FieldType } from '@objectql/types';
66

77
interface SyncOptions {
88
config?: string;
@@ -167,7 +167,7 @@ function generateObjectDefinition(table: IntrospectedTable, schema: Introspected
167167
} else {
168168
// Regular field - map SQL type to ObjectQL type
169169
const fieldType = mapSqlTypeToObjectQL(column.type, column);
170-
field.type = fieldType as any; // Type assertion needed as mapSqlTypeToObjectQL returns string
170+
field.type = fieldType;
171171

172172
// Add label
173173
field.label = formatLabel(column.name);
@@ -205,12 +205,12 @@ function generateObjectDefinition(table: IntrospectedTable, schema: Introspected
205205
/**
206206
* Map SQL native type to ObjectQL field type
207207
*/
208-
function mapSqlTypeToObjectQL(sqlType: string, column: IntrospectedColumn): string {
208+
function mapSqlTypeToObjectQL(sqlType: string, column: IntrospectedColumn): FieldType {
209209
const type = sqlType.toLowerCase();
210210

211-
// Integer types
211+
// Integer types - map to 'number'
212212
if (type.includes('int') || type.includes('serial') || type.includes('bigserial')) {
213-
return 'integer';
213+
return 'number';
214214
}
215215

216216
// Float/Decimal types
@@ -240,9 +240,9 @@ function mapSqlTypeToObjectQL(sqlType: string, column: IntrospectedColumn): stri
240240
return 'textarea';
241241
}
242242

243-
// JSON types
243+
// JSON types - map to 'object'
244244
if (type.includes('json') || type.includes('jsonb')) {
245-
return 'json';
245+
return 'object';
246246
}
247247

248248
// Binary/Blob types

0 commit comments

Comments
 (0)