SQLAlchemy support

11 views
Skip to first unread message

Timbo

unread,
Jun 11, 2009, 12:14:43 PM6/11/09
to wwwsqldesigner
Ondrej, thank you for this awesome tool. I'm working on SQLAlchemy
support but I've hit a snag. Being somewhat new to XSLT, I can see
it's power but some of its nuances are lost on me.

Here's the deal...most databases specify primary keys at the end of
the CREATE TABLE command after the columns have been specified.
SQLAlchemy, however, sets the primary_key=True parameter when it
creates a column instance. This is not a big deal except that the XML
going into the XSLT template specifies primary and unique keys after
the columns ("row" nodes in the XML) without than supplying that data
within the row nodes.

There are two solutions to this predicament of mine. 1) Maybe you can
help me with some XSLT that can read the KEY nodes while within a
template of ROWs. 2) Add "primary" attributes to the ROW nodes. To
clarify what I mean, here's an example XML output.

<?xml version="1.0" encoding="utf-8"?>
<sql>
<table x="252" y="168" name="new table">
<row name="id" null="0" autoincrement="1" primary="1"> <!-- NOTE
ADDED "primary" ATTRIBUTE -->
<datatype>sa.Integer</datatype>
</row>
<row name="new field" null="0" autoincrement="1" primary="0"> <!--
NOTE ADDED "primary" ATTRIBUTE -->
<datatype>sa.String(10)</datatype>
<default>'sada'</default>
<comment>asdfasdf</comment>
</row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
</sql>

What do you think?

-tim

Ondrej Zara

unread,
Jun 12, 2009, 2:13:33 AM6/12/09
to wwwsqld...@googlegroups.com
Hi Timbo,

your proposal #1 is surely the correct way to go. I would try something similar to this (highly simplified):

<xsl:for-each select="row">
  <xsl:value-of select="@name" />
  <xsl:variable name="rowname" select="@name" />
  <xsl:for-each select="../key[@type='PRIMARY']/part">
    <xsl:if test="$rowname = text()"> THIS IS THE PRIMARY KEY </xsl:if>
  </xsl:for-each>
</xsl:for-each>



O.



 

Timothy Farrell

unread,
Jun 12, 2009, 10:33:44 AM6/12/09
to wwwsqld...@googlegroups.com
That's exactly what I needed. I've attached a zip file. If you like,
you could add its contents to the db directory. Like web2py support, it
creates source files for interacting with tables rather than SQL from
which to create a table. SQLAlchemy users would understand how to use
the output.

Thanks for your help,

-tim
sqlalchemy.zip

Ondrej Zara

unread,
Jun 17, 2009, 2:18:00 AM6/17/09
to wwwsqld...@googlegroups.com
Hi Tim,


thanks a lot, I just added your directory to SVN. It will be included in next wwwsql release.

O.


2009/6/12 Timothy Farrell <tfar...@swgen.com>
Reply all
Reply to author
Forward
0 new messages