sqlalchemy beginner

J

Jabba Laci

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
 
J

John Gordon

In said:
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''),
 
R

Roy Smith

Jabba Laci said:
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?
 
A

alex23

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?
 
R

Roy Smith

alex23 said:
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.
 
C

Cameron Simpson

| In article
| <8832ab6d-8def-45d1-92df-baac40e1c498@t36g2000prt.googlegroups.com>,
| > > 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 <[email protected]> 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top