Introduction to SQL Alchemy - SyPy June 2013

  • 1,355 views
Uploaded on

A very brief introduction to SQLAlchemy, covering the core, ORM, database concepts and a high-level comparison to the Django ORM. …

A very brief introduction to SQLAlchemy, covering the core, ORM, database concepts and a high-level comparison to the Django ORM.

IPython notebook demo content is at http://nbviewer.ipython.org/urls/dl.dropboxusercontent.com/s/90s3abt64vxd4r4/SQLAlchemy.ipynb?token_hash=AAEWmGa8Kng0qijeH29NnPtjblOCTe387vRUxLDOpbyCKg&dl=1

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,355
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. SyPy June 2013● Introduction to SQLAlchemy - Roger Barnes● Using Robot Framework for testing,communication and world domination - Dylan Jay● Configuration management with Salt Stack -Daniel Bryan● + lightning talks● Pub
  • 2. SyPy June 2013Next SyPy - Aug 1, 2013http://bit.ly/11kHTmB
  • 3. Introduction toSQLAlchemyRoger BarnesSyPy June 2013roger@mindsocket.com.au @mindsocket
  • 4. About Me15 years software development4 years Python/Django4 months SQLAlchemy
  • 5. SQLAlchemy is...Python SQL toolkit&Object Relational Mapper
  • 6. About SQLAlchemy● Full featured● Mature, robust, documented, maintained● Flexible– Use what you need– Extend when you need– Database oriented– Doesnt dictate schema design– ...
  • 7. Enterprise!
  • 8. DB support● SQLite● Postgresql● MySQL● Oracle● MS-SQL● Firebird● Sybase● ...
  • 9. Python supportcPython 2.5+cPython 3+Jython 2.5+Pypy 1.5+
  • 10. Compared with Django ORM?● Both are good● Key philosophical design differenceDjango → Web applicationsSQLAlchemy → Database applications
  • 11. Compared with Django ORM?● Django ORM– easier to learn– less flexible– well suited for most web apps– comes with a free admin app
  • 12. Compared with Django ORM?● SQLAlchemy– harder to learn (but only a little)– massively flexible– suited to a wider range ofapplications, especially those thatbenefit from the power of anRDBMS
  • 13. Project StructureSQLAlchemy is like an onion...… or a cake
  • 14. Structure
  • 15. Core● Abstraction over Pythons DBAPI● SQL language via generativePython expressions
  • 16. Core● Good for DB performance– bulk operations– complex queries– fine-tuning– connection/tx management
  • 17. Core● Schema– Managed by a Metadata object– Declare tables, columns andother attributes– Closely aligned with DataDefinition Language
  • 18. Core● SQL Expressions– INSERT, UPDATE, DELETE– SELECT, joins, grouping– Functions, expressions, operators● Connection pooling● Backend DB dialects
  • 19. Demo
  • 20. ORMs in General● Simple case – translate between adomain object and a table row● More complex – arbitrary rowsmapped to an object● Handle relationships
  • 21. ORMs in General● Query in terms of objects● Represent class inheritance● Data validation
  • 22. SQLAlchemy ORM● Layer on top of core● Session based● Session manages object state
  • 23. SQLAlchemy ORM● 2 ways to use– Classical Mapping● Define table● Define object● Configure mapper– Modern - Declarative● Shorthand combining table metadata andclass mapping● Similar to Django ORM
  • 24. Demo
  • 25. Questions?● Other resources– SQLAlchemy - http://sqlalchemy.org/– Longer (better) introduction -http://bit.ly/13UQXVV● Contactroger@mindsocket.com.au@mindsocket