@@ -2,6 +2,7 @@ import { DataFieldAttributeFactory } from '@zenstackhq/language/factory';
22import { Client } from 'pg' ;
33import { getAttributeRef , getDbName , getFunctionRef } from '../utils' ;
44import type { IntrospectedEnum , IntrospectedSchema , IntrospectedTable , IntrospectionProvider } from './provider' ;
5+ import type { BuiltinType } from '@zenstackhq/language/ast' ;
56
67export const postgresql : IntrospectionProvider = {
78 getBuiltinType ( type ) {
@@ -78,6 +79,28 @@ export const postgresql: IntrospectionProvider = {
7879 tables,
7980 } ;
8081 } ,
82+ getDefaultDatabaseType ( type : BuiltinType ) {
83+ switch ( type ) {
84+ case 'String' :
85+ return { type : 'text' } ;
86+ case 'Boolean' :
87+ return { type : 'boolean' } ;
88+ case 'Int' :
89+ return { type : 'integer' } ;
90+ case 'BigInt' :
91+ return { type : 'bigint' } ;
92+ case 'Float' :
93+ return { type : 'double precision' } ;
94+ case 'Decimal' :
95+ return { type : 'decimal' } ;
96+ case 'DateTime' :
97+ return { type : 'timestamp' , precisition : 3 } ;
98+ case 'Json' :
99+ return { type : 'jsonb' } ;
100+ case 'Bytes' :
101+ return { type : 'bytea' } ;
102+ }
103+ } ,
81104 getDefaultValue ( { defaultValue, fieldName, services, enums } ) {
82105 const val = defaultValue . trim ( ) ;
83106 const factories : DataFieldAttributeFactory [ ] = [ ] ;
@@ -276,7 +299,7 @@ SELECT
276299 ),
277300 '[]'
278301 ) AS "options"
279-
302+
280303 FROM "pg_catalog"."pg_attribute" AS "att"
281304
282305 INNER JOIN "pg_catalog"."pg_type" AS "typ" ON "typ"."oid" = "att"."atttypid"
0 commit comments