@@ -97,57 +97,62 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
9797 rows . forEach ( ( row ) => {
9898 const field : any = { } ;
9999 const baseType = row . type . toLowerCase ( ) ;
100- if ( baseType == 'int' ) {
100+ const isPgArray = baseType . endsWith ( '[]' ) ;
101+ const normalizedBaseType = isPgArray ? baseType . slice ( 0 , - 2 ) : baseType ;
102+ if ( normalizedBaseType == 'int' ) {
101103 field . type = AdminForthDataTypes . INTEGER ;
102104 field . _underlineType = 'int' ;
103105
104- } else if ( baseType . includes ( 'float' ) || baseType . includes ( 'double' ) ) {
106+ } else if ( normalizedBaseType . includes ( 'float' ) || normalizedBaseType . includes ( 'double' ) ) {
105107 field . type = AdminForthDataTypes . FLOAT ;
106108 field . _underlineType = 'float' ;
107109
108- } else if ( baseType . includes ( 'bool' ) ) {
110+ } else if ( normalizedBaseType . includes ( 'bool' ) ) {
109111 field . type = AdminForthDataTypes . BOOLEAN ;
110112 field . _underlineType = 'bool' ;
111113
112- } else if ( baseType == 'uuid' ) {
114+ } else if ( normalizedBaseType == 'uuid' ) {
113115 field . type = AdminForthDataTypes . STRING ;
114116 field . _underlineType = 'uuid' ;
115117
116- } else if ( baseType . includes ( 'character varying' ) ) {
118+ } else if ( normalizedBaseType . includes ( 'character varying' ) ) {
117119 field . type = AdminForthDataTypes . STRING ;
118120 field . _underlineType = 'varchar' ;
119- const length = baseType . match ( / \d + / ) ;
121+ const length = normalizedBaseType . match ( / \d + / ) ;
120122 field . maxLength = length ? parseInt ( length [ 0 ] ) : null ;
121123
122- } else if ( baseType == 'text' ) {
124+ } else if ( normalizedBaseType == 'text' ) {
123125 field . type = AdminForthDataTypes . TEXT ;
124126 field . _underlineType = 'text' ;
125127
126- } else if ( baseType . includes ( 'decimal(' ) || baseType . includes ( 'numeric(' ) ) {
128+ } else if ( normalizedBaseType . includes ( 'decimal(' ) || normalizedBaseType . includes ( 'numeric(' ) ) {
127129 field . type = AdminForthDataTypes . DECIMAL ;
128130 field . _underlineType = 'decimal' ;
129- const [ precision , scale ] = baseType . match ( / \d + / g) ;
131+ const [ precision , scale ] = normalizedBaseType . match ( / \d + / g) ;
130132 field . precision = parseInt ( precision ) ;
131133 field . scale = parseInt ( scale ) ;
132134
133- } else if ( baseType == 'real' ) {
135+ } else if ( normalizedBaseType == 'real' ) {
134136 field . type = AdminForthDataTypes . FLOAT ;
135137 field . _underlineType = 'real' ;
136138
137- } else if ( baseType == 'date' ) {
139+ } else if ( normalizedBaseType == 'date' ) {
138140 field . type = AdminForthDataTypes . DATE ;
139141 field . _underlineType = 'timestamp' ;
140142
141- } else if ( baseType . includes ( 'date' ) || baseType . includes ( 'time' ) ) {
143+ } else if ( normalizedBaseType . includes ( 'date' ) || normalizedBaseType . includes ( 'time' ) ) {
142144 field . type = AdminForthDataTypes . DATETIME ;
143145 field . _underlineType = 'timestamp' ;
144- } else if ( baseType == 'json' || baseType == 'jsonb' ) {
146+ } else if ( normalizedBaseType == 'json' || normalizedBaseType == 'jsonb' ) {
145147 field . type = AdminForthDataTypes . JSON ;
146148 field . _underlineType = 'json' ;
147149 } else {
148150 field . type = 'unknown'
149151 }
150152 field . _baseTypeDebug = baseType ;
153+ if ( isPgArray ) {
154+ field . _isPgArray = true ;
155+ }
151156 field . primaryKey = row . pk == 1 ;
152157 field . default = row . dflt_value ;
153158 field . required = row . notnull && ! row . dflt_value ;
@@ -211,11 +216,22 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
211216 } else if ( field . _underlineType == 'varchar' ) {
212217 return dayjs ( value ) . toISOString ( ) ;
213218 }
219+ } else if ( field . isArray ?. enabled ) {
220+ if ( value === null || value === undefined ) {
221+ return null ;
222+ }
223+ if ( field . _isPgArray ) {
224+ return value ;
225+ }
226+ if ( field . _underlineType == 'json' ) {
227+ return JSON . stringify ( value ) ;
228+ }
229+ return JSON . stringify ( value ) ;
214230 } else if ( field . type == AdminForthDataTypes . BOOLEAN ) {
215231 return value === null ? null : ( value ? 1 : 0 ) ;
216232 } else if ( field . type == AdminForthDataTypes . JSON ) {
217233 if ( field . _underlineType == 'json' ) {
218- return value ;
234+ return typeof value === 'string' || value === null ? value : JSON . stringify ( value ) ;
219235 } else {
220236 return JSON . stringify ( value ) ;
221237 }
0 commit comments