On Tue, Apr 16, 2019 at 10:35:13AM +0200, Markus Elfring <Mar...@we...> wrote:
> >> Will such software extensions become more feasible?
> >
> > Yes, I think so.
>
> Thanks for such positive feedback.
Welcome! :-)
> > The API perhaps would be simple, something like
> >
> > class SQLObject(...):
> > @classmethod
> > def createAsSelectSQL(cls, selectFrom):
> > ...
>
> How do you think about the clarification for additional classes?
Sorry, I don't understand.
> > @classmethod
> > def createAsSelect(cls, selectFrom):
> > conn = connection or cls._connection
> > query = cls.createAsSelectSQL(selectFrom)
> > conn.query(query)
> >
> > where ``selectFrom`` is ``SelectResults`` instance. The method shod
> > construct ``CREATE TABLE ... AS SELECT ...`` but it also must construct
> > a list of columns (instances of ``col.Col`` classes) and call
> > ``cls.sqlmeta.addColumn(columnDef)`` for every column in the list.
>
> Will the determination of involved data structures need any further
> software design considerations?
That can only be determined during design and implementation.
> > And here I foresee a problem. It's possible to create a table in the
> > database but how to recreate the class with all columns on the second
> > run of the program or in another program that will use the class?
>
> Are you used to fiddle with database reflection (or introspection)?
SQLObject does some limited introspection. It can determine if a
table exists[1] and get the list[2][3] of columns and joins.
1. https://github.com/sqlobject/sqlobject/blob/ed64be0ed032055b0a6613fe3051d83a74ded566/sqlobject/main.py#L1471
2. http://sqlobject.org/SQLObject.html#automatic-class-generation
3. https://github.com/sqlobject/sqlobject/blob/ed64be0ed032055b0a6613fe3051d83a74ded566/sqlobject/postgres/pgconnection.py#L346
> Regards,
> Markus
Oleg.
--
Oleg Broytman https://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|