Re: [sqlalchemy] Creating Tables from a Schema defined in YAML

2013-08-22 Thread Monosij Dutta-Roy
Hi Kevin -

Thanks for your help. I am, however, unable to call Column on the tuple
(attrname, 'String').

I tried like this:
columns = []
for attribute in attrList:
tup = attribute, 'String'
tupC = Column(tup)   // does not work
columns.append(tup)

So Columns (tup) did not work and I also tried calling Column on the tuples
list I created in the iterator.

So my call to create a table as in:
theTable = Table (tableName, Metadata, *columns) - does not work. I also
tried w/o the column call but did not expect it to work.

So sounds like would be a 'star args' for the Column call as well but am
unable to find it.

Please let me know if I am approaching this incorrectly (I assume I am).

Also, I could generate a SQL create statement from my YAML file.

Would there be a way to use the Table command to create a table from that -
but it would defeat the purpose as if go with a different DBMS I have to
make sure the SQL is addressed? Or does sqlalchemy take care of that as
well?

If there is some documentation you could refer me to in how this dynamic
generation is implemented will be great.

Also, since it is a tuple I assume I can put in PK / FK information as well.

And I can help create some of this documentation if it does not exist. Its
a great library, very helpful, just trying to find some flexibility.

Thank you for your help.

Mono





On Thu, Aug 22, 2013 at 11:18 AM, Kevin Horn  wrote:

> On Wed, Aug 21, 2013 at 11:26 PM,  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 a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/2eY6URGd2mY/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>

-- 
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.


Re: [sqlalchemy] Creating Tables from a Schema defined in YAML

2013-08-22 Thread Kevin Horn
On Wed, Aug 21, 2013 at 11:26 PM,  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.


[sqlalchemy] Creating Tables from a Schema defined in YAML

2013-08-21 Thread monosij . forums

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

-- 
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.