On Wed, Aug 21, 2013 at 11:26 PM, <monosij.for...@gmail.com> wrote:

>
> Hello - Wondering if someone could please help me with this:
>
> I have created a schema definition file in YAML which I read into a dict.
>
> I am used to statically creating a table in this form:
> tableName = Table (theTableName, Metadata,
> Column(column1, String),
> Column(column2, String),
> Column(coulumn3, String)
> ...
> )
>
> I am trying to see if there is a way to dynamically create a table using
> the column definition in the YAML file. So it would need to iterate over
> the column names and the types.
>
> I tried with creating the string = 'Column(column1,
> String), Column(column2, String), Column(coulumn3, String) ...'
> by iterating over the dict keys and then calling as above - but that did
> not work.
>
> Just wondering if there would be another way to do this.
>
> I looked at mapper as well but then that is for objects.
>
> Thanks.
>
> Mono
>

The answer to this probably depends on exactly what your schema looks like,
but based on what you've told us so far, I would probably try to create all
the columns first, get them into a list or tuple, and then use "star args"
to pass them into the Table constructor.  Something like this:

columns = [Column(name, type) for name, type in
some_kind_of_iterable_generated_from_your_yaml]

table = Table(theTableName, Metadata, *columns)

though obviously that's a very rough example

--
Kevin Horn

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to