Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16018 > unrolled thread
| Started by | Jabba Laci <jabba.laci@gmail.com> |
|---|---|
| First post | 2011-11-21 16:56 +0100 |
| Last post | 2011-11-22 17:06 +1100 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.python
sqlalchemy beginner Jabba Laci <jabba.laci@gmail.com> - 2011-11-21 16:56 +0100
Re: sqlalchemy beginner John Gordon <gordon@panix.com> - 2011-11-21 17:08 +0000
Re: sqlalchemy beginner Roy Smith <roy@panix.com> - 2011-11-21 19:25 -0500
Re: sqlalchemy beginner alex23 <wuwei23@gmail.com> - 2011-11-21 18:51 -0800
Re: sqlalchemy beginner Roy Smith <roy@panix.com> - 2011-11-21 22:18 -0500
Re: sqlalchemy beginner Cameron Simpson <cs@zip.com.au> - 2011-11-22 17:06 +1100
| From | Jabba Laci <jabba.laci@gmail.com> |
|---|---|
| Date | 2011-11-21 16:56 +0100 |
| Subject | sqlalchemy beginner |
| Message-ID | <mailman.2906.1321891043.27778.python-list@python.org> |
Hi,
I'm reading the Essential SQLAlchemy book from O'Reilly. It explains
SqlAlch 0.4 but my current version is 0.7 and there are some
differences.
Here is an example from the book:
user_table = Table('tf_user', metadata,
Column('id', Integer, primary_key=True),
Column('user_name', Unicode(16), unique=True, nullable=False),
Column('password', Unicode(40), nullable=False),
Column('display_name', Unicode(255), default=''),
Column('created', DateTime, default=datetime.now)
)
Here I get the following warning:
SAWarning: Unicode column received non-unicode default value.
Column('display_name', Unicode(255), default=''),
Changing Unicode(255) to String(255) makes the warning disappear but
I'm not sure if it's the correct solution.
For table names, the book uses the prefix convention 'tf_' but what
does it mean? 't' is table, but what is 'f'?
Thanks,
Laszlo
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2011-11-21 17:08 +0000 |
| Message-ID | <jae0hm$qod$1@reader1.panix.com> |
| In reply to | #16018 |
In <mailman.2906.1321891043.27778.python-list@python.org> Jabba Laci <jabba.laci@gmail.com> writes:
> SAWarning: Unicode column received non-unicode default value.
> Column('display_name', Unicode(255), default=''),
Perhaps it would help to supply the default value as a Unicode string
instead of a plain string?
Column('display_name', Unicode(255), default=u''),
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2011-11-21 19:25 -0500 |
| Message-ID | <roy-38AE1C.19250321112011@news.panix.com> |
| In reply to | #16018 |
In article <mailman.2906.1321891043.27778.python-list@python.org>, Jabba Laci <jabba.laci@gmail.com> wrote: > Hi, > > I'm reading the Essential SQLAlchemy book from O'Reilly. Everytime I've worked with SQLAlchemy, I've run away screaming in the other direction. Sure, portability is a good thing, but at what cost?
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2011-11-21 18:51 -0800 |
| Message-ID | <8832ab6d-8def-45d1-92df-baac40e1c498@t36g2000prt.googlegroups.com> |
| In reply to | #16059 |
On Nov 22, 10:25 am, Roy Smith <r...@panix.com> wrote: > Everytime I've worked with SQLAlchemy, I've run away screaming in the > other direction. Sure, portability is a good thing, but at what cost? I've never found SQLAlchemy to be anything but sane and approachable. It's really worth understanding _how_ it works so you can see there's no magic happening there. What cost do you see inherit in the use of SQLAlchemy?
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2011-11-21 22:18 -0500 |
| Message-ID | <roy-F87DE4.22180421112011@news.panix.com> |
| In reply to | #16063 |
In article <8832ab6d-8def-45d1-92df-baac40e1c498@t36g2000prt.googlegroups.com>, alex23 <wuwei23@gmail.com> wrote: > On Nov 22, 10:25 am, Roy Smith <r...@panix.com> wrote: > > Everytime I've worked with SQLAlchemy, I've run away screaming in the > > other direction. Sure, portability is a good thing, but at what cost? > > I've never found SQLAlchemy to be anything but sane and approachable. > It's really worth understanding _how_ it works so you can see there's > no magic happening there. > > What cost do you see inherit in the use of SQLAlchemy? The cost of understanding how it works :-) Seriously. I understand SQL. Well, I'm not a SQL wizard, but I understand enough to do what I need to do. Whenever I have to use SQLAlchemy, I always find myself knowing exactly what SQL I want to write and scratching my head to figure out how to translate that into SQLAlchemy calls.
[toc] | [prev] | [next] | [standalone]
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2011-11-22 17:06 +1100 |
| Message-ID | <mailman.2943.1321942466.27778.python-list@python.org> |
| In reply to | #16067 |
On 21Nov2011 22:18, Roy Smith <roy@panix.com> wrote:
| In article
| <8832ab6d-8def-45d1-92df-baac40e1c498@t36g2000prt.googlegroups.com>,
| alex23 <wuwei23@gmail.com> wrote:
| > On Nov 22, 10:25?am, Roy Smith <r...@panix.com> wrote:
| > > Everytime I've worked with SQLAlchemy, I've run away screaming in the
| > > other direction. ?Sure, portability is a good thing, but at what cost?
| >
| > I've never found SQLAlchemy to be anything but sane and approachable.
| > It's really worth understanding _how_ it works so you can see there's
| > no magic happening there.
| >
| > What cost do you see inherit in the use of SQLAlchemy?
|
| The cost of understanding how it works :-)
|
| Seriously. I understand SQL. Well, I'm not a SQL wizard, but I
| understand enough to do what I need to do. Whenever I have to use
| SQLAlchemy, I always find myself knowing exactly what SQL I want to
| write and scratching my head to figure out how to translate that into
| SQLAlchemy calls.
Are you trying to go the ORM route (make classes etc mapping to SQL
entities etc)?
I ask because I avoid ORM and mostly use the SQL syntax notation, eg:
for node_id, attr, value in select( [ attrs.c.NODE_ID,
attrs.c.ATTR,
attrs.c.VALUE,
] ) \
.order_by(asc(attrs.c.NODE_ID)) \
.execute():
or:
self.attrs.delete(self.attrs.c.NODE_ID == node_id).execute()
which I find very easy to read (self.attrs is an SQLAchemy table).
ORMs seem very cool and all, but I personally prefer to work with simple
SQL level schemae and python-level objects and classes i.e. not ORM
classes but ordinary classes that cll SQLAlchemy
select/update/delete/etc methods to manipulate the db.
For me the great strengths of SQLA are that it (1) talks to many
different backend DBs and (2) removes the need to write tediously quotes
SQL because I can write python expressions like the above that map
directly to SQL statements, and SQLA does all the quoting, conversion
etc. Reliably!
Cheers,
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
I sometimes wish that people would put a little more emphasis upon the
observance of the law than they do upon its enforcement. - Calvin Coolidge
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web