@@ -91,6 +91,24 @@ class PythonContext {
9191 const schema = this . schemas [ type . schema ] ;
9292 return new PythonClass ( type . name , schema , attributeEntries ) ;
9393 }
94+
95+ viewToClass ( view : PostgresView ) : PythonClass {
96+ const attributes : PythonClassAttribute [ ] = ( this . columns [ view . id ] ?? [ ] )
97+ . map ( ( col ) => {
98+ const type = new PythonConcreteType ( this , col . format , col . is_nullable ) ;
99+ return new PythonClassAttribute ( col . name , type ) ;
100+ } ) ;
101+ return new PythonClass ( view . name , this . schemas [ view . schema ] , attributes )
102+ }
103+
104+ matViewToClass ( matview : PostgresMaterializedView ) : PythonClass {
105+ const attributes : PythonClassAttribute [ ] = ( this . columns [ matview . id ] ?? [ ] )
106+ . map ( ( col ) => {
107+ const type = new PythonConcreteType ( this , col . format , col . is_nullable ) ;
108+ return new PythonClassAttribute ( col . name , type ) ;
109+ } ) ;
110+ return new PythonClass ( matview . name , this . schemas [ matview . schema ] , attributes )
111+ }
94112}
95113
96114
@@ -249,8 +267,11 @@ export const apply = ({
249267 const py_tables = tables
250268 . filter ( ( table ) => schemas . some ( ( schema ) => schema . name === table . schema ) )
251269 . map ( ( table ) => ctx . tableToClass ( table ) ) ;
252- console . log ( 'composite_types' ) ;
270+
253271 const composite_types = types . filter ( ( type ) => type . attributes . length > 0 ) . map ( ( type ) => ctx . typeToClass ( type ) ) ;
272+ console . log ( views ) ;
273+ const py_views = views . map ( ( view ) => ctx . viewToClass ( view ) ) ;
274+ const py_matviews = materializedViews . map ( ( matview ) => ctx . matViewToClass ( matview ) ) ;
254275
255276 let output = `
256277import datetime
@@ -260,49 +281,15 @@ from pydantic import BaseModel, Field, Json
260281
261282${ concatLines ( Object . values ( ctx . user_enums ) ) }
262283
284+ ${ concatLines ( composite_types ) }
285+
263286${ concatLines ( py_tables ) }
264287
265- ${ concatLines ( composite_types ) }
288+ ${ concatLines ( py_views ) }
266289
267- ` . trim ( )
290+ ${ concatLines ( py_matviews ) }
268291
269- // ${views
270- // .filter((view) => schemas.some((schema) => schema.name === view.schema))
271- // .flatMap((view) =>
272- // generateTableStructsForOperations(
273- // schemas.find((schema) => schema.name === view.schema)!,
274- // view,
275- // columnsByTableId[view.id],
276- // types,
277- // ['Select']
278- // )
279- // )
280- // .join('\n\n') }
281-
282- // ${materializedViews
283- // .filter((materializedView) => schemas.some((schema) => schema.name === materializedView.schema))
284- // .flatMap((materializedView) =>
285- // generateTableStructsForOperations(
286- // schemas.find((schema) => schema.name === materializedView.schema)!,
287- // materializedView,
288- // columnsByTableId[materializedView.id],
289- // types,
290- // ['Select']
291- // )
292- // )
293- // .join('\n\n') }
294-
295- // ${compositeTypes
296- // .filter((compositeType) => schemas.some((schema) => schema.name === compositeType.schema))
297- // .map((compositeType) =>
298- // generateCompositeTypeStruct(
299- // schemas.find((schema) => schema.name === compositeType.schema)!,
300- // compositeType,
301- // types
302- // )
303- // )
304- // .join('\n\n') }
305- // `.trim()
292+ ` . trim ( )
306293
307294 return output
308295}
0 commit comments