SQLAlchemy: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 16: Line 16:
I tried SQLAlchemy out about a year ago then moved on. I just wrote code that talked directly to PostgreSQL. Now that I am diving into [[Flask]], I need to look at it again. Back then I was working PHP and also directly with SQL, so I felt sqlalchemy just got in my way.
I tried SQLAlchemy out about a year ago then moved on. I just wrote code that talked directly to PostgreSQL. Now that I am diving into [[Flask]], I need to look at it again. Back then I was working PHP and also directly with SQL, so I felt sqlalchemy just got in my way.


The big plus at the moment for me is that I can write one piece of code and have it talk to both [[sqlite]] files and real databases including PostgreSQL and MySQL. This make testing and developing on a laptop with sqlite and then migrating to a database server very easy. I hope.
The big plus at the moment for me is that I can write one piece of code and have it talk to both [[SQLite]] files and real databases including PostgreSQL and MySQL. This make testing and developing on a laptop with sqlite and then migrating to a database server very easy. I hope.


* Remember to do the db.session.add(obj) and db.session.commit() operations.
* Remember to set values that are nullable=False


[[Category: SQL]]
[[Category: SQL]]

Latest revision as of 21:45, 11 June 2015

SQLAlchemy is an ORM (Object Relational Mapper) for Python which means it makes the data in a SQL database accessible to Python programs as objects.

Where to turn for info

I found these pages useful in my initial foray

Official docs for .8 release

http://tspycher.com/2012/11/python-and-sqlalchemy-0-8-example/

http://www.blog.pythonlibrary.org/2012/07/01/a-simple-sqlalchemy-0-7-0-8-tutorial/

My sqlalchemy journey continues

I tried SQLAlchemy out about a year ago then moved on. I just wrote code that talked directly to PostgreSQL. Now that I am diving into Flask, I need to look at it again. Back then I was working PHP and also directly with SQL, so I felt sqlalchemy just got in my way.

The big plus at the moment for me is that I can write one piece of code and have it talk to both SQLite files and real databases including PostgreSQL and MySQL. This make testing and developing on a laptop with sqlite and then migrating to a database server very easy. I hope.

  • Remember to do the db.session.add(obj) and db.session.commit() operations.
  • Remember to set values that are nullable=False