SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
Object Relational Mapping
SQL Expressions
Table Metadata, Reflection, DDL
Engine, Connection, Transactions
Introduction to
SQLAlchemy and ORMs
@zzzeekMike Bayer
Companion Package Download:
http://techspot.zzzeek.org/sqlalchemy_tutorial.zip
Prerequisite Knowledge
• This	
  tutorial	
  assumes	
  some	
  basic	
  knowledge	
  about	
  
SQL	
  (in	
  order	
  of	
  importance):
• structure:	
  tables,	
  columns,	
  CREATE	
  TABLE,	
  etc.
• querying:	
  selecting	
  rows	
  with	
  SELECT
• modifying	
  data	
  with	
  INSERT,	
  UPDATE,	
  DELETE	
  
• joins,	
  grouping
• transactions
SQLAlchemy - Overview
• the	
  Database	
  Toolkit	
  for	
  Python
• introduced	
  2005
• end-­‐to-­‐end	
  system	
  for	
  working	
  with	
  the	
  Python	
  
DBAPI,	
  relational	
  databases,	
  and	
  the	
  SQL	
  language
• Current	
  release	
  0.8.2,	
  0.9	
  almost	
  ready
• 1.0	
  will	
  happen
SQLAlchemy Goals
• Provide	
  helpers,	
  tools	
  and	
  components	
  to	
  assist	
  and	
  
automate	
  database	
  development	
  at	
  every	
  level
• Provide	
  a	
  consistent	
  and	
  fully	
  featured	
  facade	
  over	
  
the	
  Python	
  DBAPI
• Provide	
  an	
  industrial	
  strength,	
  but	
  optional,	
  object	
  
relational	
  mapper	
  (ORM)
• Act	
  as	
  the	
  foundation	
  for	
  any	
  number	
  of	
  third	
  party	
  or	
  
in-­‐house	
  tools
SQLAlchemy Philosophies
• Bring	
  the	
  usage	
  of	
  different	
  databases	
  and	
  adapters	
  
to	
  an	
  interface	
  as	
  consistent	
  as	
  possible...
• ...but	
  still	
  expose	
  distinct	
  behaviors	
  and	
  features	
  of	
  
each	
  backend.
• Never	
  "hide"	
  the	
  database	
  or	
  its	
  concepts	
  -­‐	
  
developers	
  must	
  know	
  /	
  continue	
  to	
  think	
  in	
  SQL...
• Instead....provide	
  automation	
  and	
  DRY
• Allow	
  expression	
  of	
  DB/SQL	
  tasks	
  using	
  declarative	
  
patterns
SQLAlchemy	
  consists	
  of	
  the	
  Core	
  and	
  the	
  ORM
SQLAlchemy Overview
Third party libraries / Python core
SQLAlchemy Core
SQLAlchemy ORM
SQL Expression
Language
Dialect
Connection
Pooling
DBAPI
Schema / Types Engine
Object Relational Mapper (ORM)
Database
SQLAlchemy - Core
• Engine	
  -­‐	
  a	
  registry	
  which	
  provides	
  connectivity	
  to	
  a	
  
particular	
  database	
  server.
• Dialect	
  -­‐	
  interprets	
  generic	
  SQL	
  and	
  database	
  
commands	
  in	
  terms	
  of	
  a	
  specific	
  DBAPI	
  and	
  database	
  
backend.
• Connection	
  Pool	
  -­‐	
  holds	
  a	
  collection	
  of	
  database	
  
connections	
  in	
  memory	
  for	
  fast	
  re-­‐use.
• SQL	
  Expression	
  Language	
  -­‐	
  Allows	
  SQL	
  statements	
  
to	
  be	
  written	
  using	
  Python	
  expressions
• Schema	
  /	
  Types	
  -­‐	
  Uses	
  Python	
  objects	
  to	
  represent	
  
tables,	
  columns,	
  and	
  datatypes.
SQLAlchemy - ORM
• Allows	
  construction	
  of	
  Python	
  objects	
  which	
  can	
  be	
  
mapped	
  to	
  relational	
  database	
  tables.
• Transparently	
  persists	
  objects	
  into	
  their	
  
corresponding	
  database	
  tables	
  using	
  the	
  unit	
  of	
  work	
  
pattern.
• Provides	
  a	
  query	
  system	
  which	
  loads	
  objects	
  and	
  
attributes	
  using	
  SQL	
  generated	
  from	
  mappings.
• Builds	
  on	
  top	
  of	
  the	
  Core	
  -­‐	
  uses	
  the	
  Core	
  to	
  generate	
  
SQL	
  and	
  talk	
  to	
  the	
  database.
• Presents	
  a	
  slightly	
  more	
  object	
  centric	
  perspective,	
  
as	
  opposed	
  to	
  a	
  schema	
  centric	
  perspective.
Can	
  be	
  learned	
  from	
  the	
  inside	
  out,	
  or	
  outside	
  in
SQLAlchemy is like an Onion
Object Relational Mapping
SQL Expressions
Table Metadata, Reflection, DDL
Engine, Connection, Transactions
Object Relational Mapping
SQL Expressions
Table Metadata, Reflection, DDL
Engine, Connection, Transactions
Level 1,
Engine,
Connection,
Transactions
The Python DBAPI
• DBAPI	
  -­‐	
  PEP-­‐0249,	
  Python	
  Database	
  API
• The	
  de-­‐facto	
  system	
  for	
  providing	
  Python	
  database	
  
interfaces
• There	
  are	
  many	
  DBAPI	
  implementations	
  available,	
  
most	
  databases	
  have	
  more	
  than	
  one
• Features/performance/stability/API	
  quirks/
maintenance	
  vary	
  wildly
DBAPI - Nutshell
import psycopg2
connection = psycopg2.connect("scott", "tiger", "test")
cursor = connection.cursor()
cursor.execute(
"select emp_id, emp_name from employee "
"where emp_id=%(emp_id)s",
{'emp_id':5})
emp_name = cursor.fetchone()[1]
cursor.close()
cursor = connection.cursor()
cursor.execute(
"insert into employee_of_month "
"(emp_name) values (%(emp_name)s)",
{"emp_name":emp_name})
cursor.close()
connection.commit()
Important DBAPI Facts
• DBAPI	
  assumes	
  that	
  a	
  transaction	
  is	
  always	
  in	
  
progress.	
  	
  There	
  is	
  no	
  begin()	
  method,	
  only	
  commit()	
  
and	
  rollback().
• DBAPI	
  encourages	
  bound	
  parameters,	
  via	
  the	
  
execute()	
  and	
  executemany()	
  methods.	
  	
  But	
  has	
  six	
  
different	
  formats.
• All	
  DBAPIs	
  have	
  inconsistencies	
  regarding	
  datatypes,	
  
primary	
  key	
  generation,	
  custom	
  database	
  features,	
  
result/cursor	
  behavior
• DBAPI	
  has	
  it's	
  own	
  exception	
  hierarchy,	
  which	
  
SQLAlchemy	
  exposes	
  directly	
  in	
  a	
  generic	
  namespace.
SQLAlchemy and the DBAPI
• The	
  first	
  layer	
  in	
  SQLAlchemy	
  is	
  known	
  as	
  the	
  
Engine,	
  which	
  is	
  the	
  object	
  that	
  maintains	
  the	
  
classical	
  DBAPI	
  interaction.
.venv/bin/sliderepl 01_engine.py
Engine - Usage
Engine Facts
• Executing	
  via	
  the	
  Engine	
  directly	
  is	
  called	
  
connectionless	
  execution	
  -­‐	
  the	
  Engine	
  connects	
  and	
  
disconnects	
  for	
  us.
• Using	
  a	
  Connection	
  is	
  called	
  explicit	
  execution.	
  	
  	
  
We	
  control	
  the	
  span	
  of	
  a	
  connection	
  in	
  use.
• Engine	
  usually	
  uses	
  a	
  connection	
  pool,	
  which	
  means	
  
"disconnecting"	
  often	
  means	
  the	
  connection	
  is	
  just	
  
returned	
  to	
  the	
  pool.
• The	
  SQL	
  we	
  send	
  to	
  engine.execute()	
  as	
  a	
  string	
  is	
  
not	
  modified,	
  is	
  consumed	
  by	
  the	
  DBAPI	
  verbatim.
Object Relational Mapping
SQL Expressions
Table Metadata, Reflection, DDL
Engine, Connection, Transactions
Level 2, Table
Metadata,
Reflection, DDL
What is "Metadata"?
• Popularized	
  by	
  Martin	
  Fowler,	
  Patterns	
  of	
  Enterprise	
  
Architecture
• Describes	
  the	
  structure	
  of	
  the	
  database,	
  i.e.	
  tables,	
  
columns,	
  constraints,	
  in	
  terms	
  of	
  data	
  structures	
  in	
  
Python
• Serves	
  as	
  the	
  basis	
  for	
  SQL	
  generation	
  and	
  object	
  
relational	
  mapping
• Can	
  generate	
  to	
  a	
  schema
• Can	
  be	
  generated	
  from	
  a	
  schema
.venv/bin/sliderepl 02_metadata.py
MetaData and Table
Some Basic Types
• Integer()	
  -­‐	
  basic	
  integer	
  type,	
  generates	
  INT
• String()	
  -­‐	
  ASCII	
  strings,	
  generates	
  VARCHAR
• Unicode()	
  -­‐	
  Unicode	
  strings	
  -­‐	
  generates	
  VARCHAR,	
  
NVARCHAR	
  depending	
  on	
  database
• Boolean()	
  -­‐	
  generates	
  BOOLEAN,	
  INT,	
  TINYINT
• DateTime()	
  -­‐	
  generates	
  DATETIME	
  or	
  
TIMESTAMP,	
  returns	
  Python	
  datetime()	
  objects
• Float()	
  -­‐	
  floating	
  point	
  values
• Numeric()	
  -­‐	
  precision	
  numerics	
  using	
  Python	
  
Decimal()
CREATE and DROP
• metadata.create_all(engine,
checkfirst=<True|False>) emits	
  CREATE	
  
statements	
  for	
  all	
  tables.
• table.create(engine,
checkfirst=<True|False>)	
  emits	
  CREATE	
  for	
  
a	
  single	
  table.
• metadata.drop_all(engine,
checkfirst=<True|False>)	
  emits	
  DROP	
  
statements	
  for	
  all	
  tables.
• table.drop(engine, checkfirst=<True|
False>)	
  emits	
  DROP	
  for	
  a	
  single	
  table.
Object Relational Mapping
SQL Expressions
Table Metadata, Reflection, DDL
Engine, Connection, Transactions
Level 3, SQL
Expressions
SQL Expressions
• The	
  SQL	
  Expression	
  system	
  builds	
  upon	
  Table	
  
Metadata	
  in	
  order	
  to	
  compose	
  SQL	
  statements	
  in	
  
Python.
• We	
  will	
  build	
  Python	
  objects	
  that	
  represent	
  individual	
  
SQL	
  strings	
  (statements)	
  we'd	
  send	
  to	
  the	
  database.
• These	
  objects	
  are	
  composed	
  of	
  other	
  objects	
  that	
  
each	
  represent	
  some	
  unit	
  of	
  SQL,	
  like	
  a	
  comparison,	
  a	
  
SELECT	
  statement,	
  a	
  conjunction	
  such	
  as	
  AND	
  or	
  OR.
• We	
  work	
  with	
  these	
  objects	
  in	
  Python,	
  which	
  are	
  then	
  
converted	
  to	
  strings	
  when	
  we	
  "execute"	
  them	
  (as	
  well	
  
as	
  if	
  we	
  print	
  them).
.venv/bin/sliderepl 03_sql_expressions.py
SQL Expressions
Object Relational Mapping
SQL Expressions
Table Metadata, Reflection, DDL
Engine, Connection, Transactions
Level 4, Object
Relational
Mapping
Object Relational Mapping
• Object	
  Relational	
  Mapping,	
  or	
  ORM,	
  is	
  the	
  process	
  of	
  
associating	
  object	
  oriented	
  classes	
  with	
  database	
  
tables.
• We	
  refer	
  to	
  the	
  set	
  of	
  object	
  oriented	
  classes	
  as	
  a	
  
domain	
  model.
The	
  most	
  basic	
  task	
  is	
  to	
  translate	
  between	
  a	
  domain	
  
object	
  and	
  a	
  table	
  row.
What does an ORM Do?
DatabaseApplication
Domain Object Table Row
object.save()
class.load()
Some	
  ORMs	
  can	
  also	
  represent	
  arbitrary	
  rows	
  as	
  domain	
  
objects	
  within	
  the	
  application,	
  that	
  is,	
  rows	
  derived	
  from	
  
SELECT	
  statements	
  or	
  views.
What does an ORM Do?
DatabaseApplication
Domain Object
SELECT statement
row
Table 1 row
Table 2 row
Most	
  ORMs	
  also	
  represent	
  basic	
  compositions,	
  primarily	
  
one-­‐to-­‐many	
  and	
  many-­‐to-­‐one,	
  using	
  foreign	
  key	
  
associations.
What does an ORM Do?
Application Database
Parent Object Table 1 Row
Table 2 Row
Child Object
Child Object
Table 2 Row
fk reference
fk reference
many to one
collection
many to one
one to many
What does an ORM Do?
• Other	
  things	
  ORMs	
  do:
• provide	
  a	
  means	
  of	
  querying	
  the	
  database	
  in	
  terms	
  of	
  
the	
  domain	
  model	
  structure
• Some	
  can	
  represent	
  class	
  inheritance	
  hierarchies	
  
using	
  a	
  variety	
  of	
  schemes
• Some	
  can	
  handle	
  "sharding"	
  of	
  data,	
  i.e.	
  storing	
  a	
  
domain	
  model	
  across	
  multiple	
  schemas	
  or	
  databases
• Provide	
  various	
  patterns	
  for	
  concurrency,	
  including	
  
row	
  versioning
• Provide	
  patterns	
  for	
  data	
  validation	
  and	
  coercion
The	
  two	
  general	
  styles	
  of	
  ORM	
  are	
  Active	
  Record	
  and	
  
Data	
  Mapper.	
  	
  Active	
  Record	
  has	
  domain	
  objects	
  handle	
  
their	
  own	
  persistence:
Flavors of ORM
user_record = User(name="ed", fullname="Ed Jones")
user_record.save()
user_record = User.query(name='ed').fetch()
user_record.fullname = "Edward Jones"
user_record.save()
The	
  Data	
  Mapper	
  approach	
  tries	
  to	
  keep	
  the	
  details	
  of	
  
persistence	
  separate	
  from	
  the	
  object	
  being	
  persisted.
Flavors of ORM
dbsession = start_session()
user_record = User(name="ed", fullname="Ed Jones")
dbsession.add(user_record)
user_record = dbsession.query(User).filter(name='ed').first()
user_record.fullname = "Edward Jones"
dbsession.commit()
ORMs	
  may	
  also	
  provide	
  different	
  configurational	
  patterns.	
  
Most	
  use	
  an	
  "all-­‐at-­‐once",	
  or	
  declarative	
  style	
  where	
  class	
  
and	
  table	
  information	
  is	
  together.
Flavors of ORM
# a hypothetical declarative system
class User(ORMObject):
tablename = 'user'
name = String(length=50)
fullname = String(length=100)
class Address(ORMObject):
tablename = 'address'
email_address = String(length=100)
user = many_to_one("User")
A	
  less	
  common	
  style	
  keeps	
  the	
  declaration	
  of	
  domain	
  
model	
  and	
  table	
  metadata	
  separate.
Flavors of ORM
# class is declared without any awareness of database
class User(object):
def __init__(self, name, username):
self.name = name
self.username = username
# elsewhere, it's associated with a database table
mapper(
User,
Table("user", metadata,
Column("name", String(50)),
Column("fullname", String(100))
)
)
SQLAlchemy ORM
• The	
  SQLAlchemy	
  ORM	
  is	
  essentially	
  a	
  data	
  mapper	
  
style	
  ORM.
• Modern	
  versions	
  use	
  declarative	
  configuration;	
  the	
  
"domain	
  and	
  schema	
  separate"	
  configuration	
  model	
  
is	
  present	
  underneath	
  this	
  layer.
• The	
  ORM	
  builds	
  upon	
  SQLAlchemy	
  Core,	
  and	
  many	
  
of	
  the	
  SQL	
  Expression	
  concepts	
  are	
  present	
  when	
  
working	
  with	
  the	
  ORM	
  as	
  well.	
  
• In	
  contrast	
  to	
  the	
  SQL	
  Expression	
  language,	
  which	
  
presents	
  a	
  schema-­‐centric	
  view	
  of	
  data,	
  it	
  presents	
  a	
  
domain-­‐model	
  centric	
  view	
  of	
  data.
Key ORM Patterns
• Unit	
  of	
  Work	
  -­‐	
  objects	
  are	
  maintained	
  by	
  a	
  system	
  that	
  
tracks	
  changes	
  over	
  the	
  course	
  of	
  a	
  transaction,	
  and	
  flushes	
  
pending	
  changes	
  periodically,	
  in	
  a	
  transparent	
  or	
  semi-­‐
transparent	
  manner
• Identity	
  Map	
  -­‐	
  objects	
  are	
  tracked	
  by	
  their	
  primary	
  key	
  
within	
  the	
  unit	
  of	
  work,	
  and	
  are	
  kept	
  unique	
  on	
  that	
  primary	
  
key	
  identity.
• Lazy	
  Loading	
  -­‐	
  Some	
  attributes	
  of	
  an	
  object	
  may	
  emit	
  
additional	
  SQL	
  queries	
  when	
  they	
  are	
  accessed.
• Eager	
  Loading	
  -­‐	
  Multiple	
  tables	
  are	
  queried	
  at	
  once	
  in	
  order	
  
to	
  load	
  related	
  objects	
  and	
  collections.
• Method	
  Chaining	
  -­‐	
  queries	
  are	
  composed	
  using	
  a	
  string	
  of	
  
method	
  calls	
  which	
  each	
  return	
  a	
  new	
  query	
  object.
.venv/bin/sliderepl 04_orm.py
ORM Walkthrough
Object Relational Mapping
SQL Expressions
Table Metadata, Reflection, DDL
Engine, Connection, Transactions
Thanks !
http://www.sqlalchemy.org
@zzzeek

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Advanced regular expressions
Advanced regular expressionsAdvanced regular expressions
Advanced regular expressions
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL
 
Joins
Joins Joins
Joins
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
 
Joins
JoinsJoins
Joins
 
python and database
python and databasepython and database
python and database
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
 
Implementing the IO Monad in Scala
Implementing the IO Monad in ScalaImplementing the IO Monad in Scala
Implementing the IO Monad in Scala
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
 
Sql (DBMS)
Sql (DBMS)Sql (DBMS)
Sql (DBMS)
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
 
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String FormattingPython Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
 
Oracle APEX Cheat Sheet
Oracle APEX Cheat SheetOracle APEX Cheat Sheet
Oracle APEX Cheat Sheet
 
Xhtml
XhtmlXhtml
Xhtml
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 

Andere mochten auch

エキPy lt repoze.whoの紹介
エキPy lt repoze.whoの紹介エキPy lt repoze.whoの紹介
エキPy lt repoze.whoの紹介Atsushi Odagiri
 
Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with PythonMark Rees
 
Python BCN Introduction to SQLAlchemy
Python BCN Introduction to SQLAlchemyPython BCN Introduction to SQLAlchemy
Python BCN Introduction to SQLAlchemytheManda
 
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...PostgresOpen
 
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenDavid Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenPostgresOpen
 
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres OpenKeith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres OpenPostgresOpen
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenPostgresOpen
 
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013PostgresOpen
 
Kevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres OpenPostgresOpen
 
Keith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres OpenKeith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres OpenPostgresOpen
 
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...PostgresOpen
 
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...PostgresOpen
 
Islamabad PUG - 7th Meetup - performance tuning
Islamabad PUG - 7th Meetup - performance tuningIslamabad PUG - 7th Meetup - performance tuning
Islamabad PUG - 7th Meetup - performance tuningUmair Shahid
 
Islamabad PUG - 7th meetup - performance tuning
Islamabad PUG - 7th meetup - performance tuningIslamabad PUG - 7th meetup - performance tuning
Islamabad PUG - 7th meetup - performance tuningUmair Shahid
 
Robert Haas Query Planning Gone Wrong Presentation @ Postgres Open
Robert Haas Query Planning Gone Wrong Presentation @ Postgres OpenRobert Haas Query Planning Gone Wrong Presentation @ Postgres Open
Robert Haas Query Planning Gone Wrong Presentation @ Postgres OpenPostgresOpen
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Denish Patel
 
Steve Singer - Managing PostgreSQL with Puppet @ Postgres Open
Steve Singer - Managing PostgreSQL with Puppet @ Postgres OpenSteve Singer - Managing PostgreSQL with Puppet @ Postgres Open
Steve Singer - Managing PostgreSQL with Puppet @ Postgres OpenPostgresOpen
 
PoPostgreSQL Web Projects: From Start to FinishStart To Finish
PoPostgreSQL Web Projects: From Start to FinishStart To FinishPoPostgreSQL Web Projects: From Start to FinishStart To Finish
PoPostgreSQL Web Projects: From Start to FinishStart To Finishelliando dias
 
Koichi Suzuki - Postgres-XC Dynamic Cluster Management @ Postgres Open
Koichi Suzuki - Postgres-XC Dynamic Cluster  Management @ Postgres OpenKoichi Suzuki - Postgres-XC Dynamic Cluster  Management @ Postgres Open
Koichi Suzuki - Postgres-XC Dynamic Cluster Management @ Postgres OpenPostgresOpen
 
Gbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfsGbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfsGiuseppe Broccolo
 

Andere mochten auch (20)

エキPy lt repoze.whoの紹介
エキPy lt repoze.whoの紹介エキPy lt repoze.whoの紹介
エキPy lt repoze.whoの紹介
 
Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with Python
 
Python BCN Introduction to SQLAlchemy
Python BCN Introduction to SQLAlchemyPython BCN Introduction to SQLAlchemy
Python BCN Introduction to SQLAlchemy
 
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
 
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenDavid Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
 
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres OpenKeith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
 
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
 
Kevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter - PostgreSQL Backup and Recovery Methods @ Postgres Open
 
Keith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres OpenKeith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres Open
 
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...Selena Deckelmann - Sane Schema Management with  Alembic and SQLAlchemy @ Pos...
Selena Deckelmann - Sane Schema Management with Alembic and SQLAlchemy @ Pos...
 
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
 
Islamabad PUG - 7th Meetup - performance tuning
Islamabad PUG - 7th Meetup - performance tuningIslamabad PUG - 7th Meetup - performance tuning
Islamabad PUG - 7th Meetup - performance tuning
 
Islamabad PUG - 7th meetup - performance tuning
Islamabad PUG - 7th meetup - performance tuningIslamabad PUG - 7th meetup - performance tuning
Islamabad PUG - 7th meetup - performance tuning
 
Robert Haas Query Planning Gone Wrong Presentation @ Postgres Open
Robert Haas Query Planning Gone Wrong Presentation @ Postgres OpenRobert Haas Query Planning Gone Wrong Presentation @ Postgres Open
Robert Haas Query Planning Gone Wrong Presentation @ Postgres Open
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
 
Steve Singer - Managing PostgreSQL with Puppet @ Postgres Open
Steve Singer - Managing PostgreSQL with Puppet @ Postgres OpenSteve Singer - Managing PostgreSQL with Puppet @ Postgres Open
Steve Singer - Managing PostgreSQL with Puppet @ Postgres Open
 
PoPostgreSQL Web Projects: From Start to FinishStart To Finish
PoPostgreSQL Web Projects: From Start to FinishStart To FinishPoPostgreSQL Web Projects: From Start to FinishStart To Finish
PoPostgreSQL Web Projects: From Start to FinishStart To Finish
 
Koichi Suzuki - Postgres-XC Dynamic Cluster Management @ Postgres Open
Koichi Suzuki - Postgres-XC Dynamic Cluster  Management @ Postgres OpenKoichi Suzuki - Postgres-XC Dynamic Cluster  Management @ Postgres Open
Koichi Suzuki - Postgres-XC Dynamic Cluster Management @ Postgres Open
 
Gbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfsGbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfs
 

Ähnlich wie Michael Bayer Introduction to SQLAlchemy @ Postgres Open

Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsRichie Rump
 
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami
 
Entity framework introduction sesion-1
Entity framework introduction   sesion-1Entity framework introduction   sesion-1
Entity framework introduction sesion-1Usama Nada
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sqlŁukasz Grala
 
Rajnish singh(presentation on oracle )
Rajnish singh(presentation on  oracle )Rajnish singh(presentation on  oracle )
Rajnish singh(presentation on oracle )Rajput Rajnish
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2Eric Nelson
 
Sage 300 ERP: Technical Tour of Diagnostic Tools
Sage 300 ERP: Technical Tour of Diagnostic ToolsSage 300 ERP: Technical Tour of Diagnostic Tools
Sage 300 ERP: Technical Tour of Diagnostic ToolsSage 300 ERP CS
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionMazenetsolution
 
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...MediaMongrels Ltd
 
Querying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuerying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuyVo27
 
05 entity framework
05 entity framework05 entity framework
05 entity frameworkglubox
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframeworkErhwen Kuo
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)David McCarter
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)David McCarter
 
Learn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstLearn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstJibran Rasheed Khan
 
Entity framework 4.0
Entity framework 4.0Entity framework 4.0
Entity framework 4.0Abhishek Sur
 
Python SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabasePython SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabaseElangovanTechNotesET
 

Ähnlich wie Michael Bayer Introduction to SQLAlchemy @ Postgres Open (20)

Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
 
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
 
Entity framework introduction sesion-1
Entity framework introduction   sesion-1Entity framework introduction   sesion-1
Entity framework introduction sesion-1
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql
 
Rajnish singh(presentation on oracle )
Rajnish singh(presentation on  oracle )Rajnish singh(presentation on  oracle )
Rajnish singh(presentation on oracle )
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
 
Ado
AdoAdo
Ado
 
Sage 300 ERP: Technical Tour of Diagnostic Tools
Sage 300 ERP: Technical Tour of Diagnostic ToolsSage 300 ERP: Technical Tour of Diagnostic Tools
Sage 300 ERP: Technical Tour of Diagnostic Tools
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
 
Querying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuerying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptx
 
05 entity framework
05 entity framework05 entity framework
05 entity framework
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Learn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstLearn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database First
 
Entity framework 4.0
Entity framework 4.0Entity framework 4.0
Entity framework 4.0
 
Python SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabasePython SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite Database
 

Mehr von PostgresOpen

Craig Kerstiens - Scalable Uniques in Postgres @ Postgres Open
Craig Kerstiens - Scalable Uniques in Postgres @ Postgres OpenCraig Kerstiens - Scalable Uniques in Postgres @ Postgres Open
Craig Kerstiens - Scalable Uniques in Postgres @ Postgres OpenPostgresOpen
 
John Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres OpenJohn Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres OpenPostgresOpen
 
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres Open
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres OpenRobert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres Open
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres OpenPostgresOpen
 
Michael Paquier - Taking advantage of custom bgworkers @ Postgres Open
Michael Paquier - Taking advantage of custom bgworkers @ Postgres OpenMichael Paquier - Taking advantage of custom bgworkers @ Postgres Open
Michael Paquier - Taking advantage of custom bgworkers @ Postgres OpenPostgresOpen
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenPostgresOpen
 
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013PostgresOpen
 

Mehr von PostgresOpen (6)

Craig Kerstiens - Scalable Uniques in Postgres @ Postgres Open
Craig Kerstiens - Scalable Uniques in Postgres @ Postgres OpenCraig Kerstiens - Scalable Uniques in Postgres @ Postgres Open
Craig Kerstiens - Scalable Uniques in Postgres @ Postgres Open
 
John Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres OpenJohn Melesky - Federating Queries Using Postgres FDW @ Postgres Open
John Melesky - Federating Queries Using Postgres FDW @ Postgres Open
 
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres Open
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres OpenRobert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres Open
Robert Bernier - Recovering From A Damaged PostgreSQL Cluster @ Postgres Open
 
Michael Paquier - Taking advantage of custom bgworkers @ Postgres Open
Michael Paquier - Taking advantage of custom bgworkers @ Postgres OpenMichael Paquier - Taking advantage of custom bgworkers @ Postgres Open
Michael Paquier - Taking advantage of custom bgworkers @ Postgres Open
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
 
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
 

Kürzlich hochgeladen

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 

Kürzlich hochgeladen (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 

Michael Bayer Introduction to SQLAlchemy @ Postgres Open

  • 1. Object Relational Mapping SQL Expressions Table Metadata, Reflection, DDL Engine, Connection, Transactions Introduction to SQLAlchemy and ORMs @zzzeekMike Bayer Companion Package Download: http://techspot.zzzeek.org/sqlalchemy_tutorial.zip
  • 2. Prerequisite Knowledge • This  tutorial  assumes  some  basic  knowledge  about   SQL  (in  order  of  importance): • structure:  tables,  columns,  CREATE  TABLE,  etc. • querying:  selecting  rows  with  SELECT • modifying  data  with  INSERT,  UPDATE,  DELETE   • joins,  grouping • transactions
  • 3. SQLAlchemy - Overview • the  Database  Toolkit  for  Python • introduced  2005 • end-­‐to-­‐end  system  for  working  with  the  Python   DBAPI,  relational  databases,  and  the  SQL  language • Current  release  0.8.2,  0.9  almost  ready • 1.0  will  happen
  • 4. SQLAlchemy Goals • Provide  helpers,  tools  and  components  to  assist  and   automate  database  development  at  every  level • Provide  a  consistent  and  fully  featured  facade  over   the  Python  DBAPI • Provide  an  industrial  strength,  but  optional,  object   relational  mapper  (ORM) • Act  as  the  foundation  for  any  number  of  third  party  or   in-­‐house  tools
  • 5. SQLAlchemy Philosophies • Bring  the  usage  of  different  databases  and  adapters   to  an  interface  as  consistent  as  possible... • ...but  still  expose  distinct  behaviors  and  features  of   each  backend. • Never  "hide"  the  database  or  its  concepts  -­‐   developers  must  know  /  continue  to  think  in  SQL... • Instead....provide  automation  and  DRY • Allow  expression  of  DB/SQL  tasks  using  declarative   patterns
  • 6. SQLAlchemy  consists  of  the  Core  and  the  ORM SQLAlchemy Overview Third party libraries / Python core SQLAlchemy Core SQLAlchemy ORM SQL Expression Language Dialect Connection Pooling DBAPI Schema / Types Engine Object Relational Mapper (ORM) Database
  • 7. SQLAlchemy - Core • Engine  -­‐  a  registry  which  provides  connectivity  to  a   particular  database  server. • Dialect  -­‐  interprets  generic  SQL  and  database   commands  in  terms  of  a  specific  DBAPI  and  database   backend. • Connection  Pool  -­‐  holds  a  collection  of  database   connections  in  memory  for  fast  re-­‐use. • SQL  Expression  Language  -­‐  Allows  SQL  statements   to  be  written  using  Python  expressions • Schema  /  Types  -­‐  Uses  Python  objects  to  represent   tables,  columns,  and  datatypes.
  • 8. SQLAlchemy - ORM • Allows  construction  of  Python  objects  which  can  be   mapped  to  relational  database  tables. • Transparently  persists  objects  into  their   corresponding  database  tables  using  the  unit  of  work   pattern. • Provides  a  query  system  which  loads  objects  and   attributes  using  SQL  generated  from  mappings. • Builds  on  top  of  the  Core  -­‐  uses  the  Core  to  generate   SQL  and  talk  to  the  database. • Presents  a  slightly  more  object  centric  perspective,   as  opposed  to  a  schema  centric  perspective.
  • 9. Can  be  learned  from  the  inside  out,  or  outside  in SQLAlchemy is like an Onion Object Relational Mapping SQL Expressions Table Metadata, Reflection, DDL Engine, Connection, Transactions
  • 10. Object Relational Mapping SQL Expressions Table Metadata, Reflection, DDL Engine, Connection, Transactions Level 1, Engine, Connection, Transactions
  • 11. The Python DBAPI • DBAPI  -­‐  PEP-­‐0249,  Python  Database  API • The  de-­‐facto  system  for  providing  Python  database   interfaces • There  are  many  DBAPI  implementations  available,   most  databases  have  more  than  one • Features/performance/stability/API  quirks/ maintenance  vary  wildly
  • 12. DBAPI - Nutshell import psycopg2 connection = psycopg2.connect("scott", "tiger", "test") cursor = connection.cursor() cursor.execute( "select emp_id, emp_name from employee " "where emp_id=%(emp_id)s", {'emp_id':5}) emp_name = cursor.fetchone()[1] cursor.close() cursor = connection.cursor() cursor.execute( "insert into employee_of_month " "(emp_name) values (%(emp_name)s)", {"emp_name":emp_name}) cursor.close() connection.commit()
  • 13. Important DBAPI Facts • DBAPI  assumes  that  a  transaction  is  always  in   progress.    There  is  no  begin()  method,  only  commit()   and  rollback(). • DBAPI  encourages  bound  parameters,  via  the   execute()  and  executemany()  methods.    But  has  six   different  formats. • All  DBAPIs  have  inconsistencies  regarding  datatypes,   primary  key  generation,  custom  database  features,   result/cursor  behavior • DBAPI  has  it's  own  exception  hierarchy,  which   SQLAlchemy  exposes  directly  in  a  generic  namespace.
  • 14. SQLAlchemy and the DBAPI • The  first  layer  in  SQLAlchemy  is  known  as  the   Engine,  which  is  the  object  that  maintains  the   classical  DBAPI  interaction.
  • 16. Engine Facts • Executing  via  the  Engine  directly  is  called   connectionless  execution  -­‐  the  Engine  connects  and   disconnects  for  us. • Using  a  Connection  is  called  explicit  execution.       We  control  the  span  of  a  connection  in  use. • Engine  usually  uses  a  connection  pool,  which  means   "disconnecting"  often  means  the  connection  is  just   returned  to  the  pool. • The  SQL  we  send  to  engine.execute()  as  a  string  is   not  modified,  is  consumed  by  the  DBAPI  verbatim.
  • 17. Object Relational Mapping SQL Expressions Table Metadata, Reflection, DDL Engine, Connection, Transactions Level 2, Table Metadata, Reflection, DDL
  • 18. What is "Metadata"? • Popularized  by  Martin  Fowler,  Patterns  of  Enterprise   Architecture • Describes  the  structure  of  the  database,  i.e.  tables,   columns,  constraints,  in  terms  of  data  structures  in   Python • Serves  as  the  basis  for  SQL  generation  and  object   relational  mapping • Can  generate  to  a  schema • Can  be  generated  from  a  schema
  • 20. Some Basic Types • Integer()  -­‐  basic  integer  type,  generates  INT • String()  -­‐  ASCII  strings,  generates  VARCHAR • Unicode()  -­‐  Unicode  strings  -­‐  generates  VARCHAR,   NVARCHAR  depending  on  database • Boolean()  -­‐  generates  BOOLEAN,  INT,  TINYINT • DateTime()  -­‐  generates  DATETIME  or   TIMESTAMP,  returns  Python  datetime()  objects • Float()  -­‐  floating  point  values • Numeric()  -­‐  precision  numerics  using  Python   Decimal()
  • 21. CREATE and DROP • metadata.create_all(engine, checkfirst=<True|False>) emits  CREATE   statements  for  all  tables. • table.create(engine, checkfirst=<True|False>)  emits  CREATE  for   a  single  table. • metadata.drop_all(engine, checkfirst=<True|False>)  emits  DROP   statements  for  all  tables. • table.drop(engine, checkfirst=<True| False>)  emits  DROP  for  a  single  table.
  • 22. Object Relational Mapping SQL Expressions Table Metadata, Reflection, DDL Engine, Connection, Transactions Level 3, SQL Expressions
  • 23. SQL Expressions • The  SQL  Expression  system  builds  upon  Table   Metadata  in  order  to  compose  SQL  statements  in   Python. • We  will  build  Python  objects  that  represent  individual   SQL  strings  (statements)  we'd  send  to  the  database. • These  objects  are  composed  of  other  objects  that   each  represent  some  unit  of  SQL,  like  a  comparison,  a   SELECT  statement,  a  conjunction  such  as  AND  or  OR. • We  work  with  these  objects  in  Python,  which  are  then   converted  to  strings  when  we  "execute"  them  (as  well   as  if  we  print  them).
  • 25. Object Relational Mapping SQL Expressions Table Metadata, Reflection, DDL Engine, Connection, Transactions Level 4, Object Relational Mapping
  • 26. Object Relational Mapping • Object  Relational  Mapping,  or  ORM,  is  the  process  of   associating  object  oriented  classes  with  database   tables. • We  refer  to  the  set  of  object  oriented  classes  as  a   domain  model.
  • 27. The  most  basic  task  is  to  translate  between  a  domain   object  and  a  table  row. What does an ORM Do? DatabaseApplication Domain Object Table Row object.save() class.load()
  • 28. Some  ORMs  can  also  represent  arbitrary  rows  as  domain   objects  within  the  application,  that  is,  rows  derived  from   SELECT  statements  or  views. What does an ORM Do? DatabaseApplication Domain Object SELECT statement row Table 1 row Table 2 row
  • 29. Most  ORMs  also  represent  basic  compositions,  primarily   one-­‐to-­‐many  and  many-­‐to-­‐one,  using  foreign  key   associations. What does an ORM Do? Application Database Parent Object Table 1 Row Table 2 Row Child Object Child Object Table 2 Row fk reference fk reference many to one collection many to one one to many
  • 30. What does an ORM Do? • Other  things  ORMs  do: • provide  a  means  of  querying  the  database  in  terms  of   the  domain  model  structure • Some  can  represent  class  inheritance  hierarchies   using  a  variety  of  schemes • Some  can  handle  "sharding"  of  data,  i.e.  storing  a   domain  model  across  multiple  schemas  or  databases • Provide  various  patterns  for  concurrency,  including   row  versioning • Provide  patterns  for  data  validation  and  coercion
  • 31. The  two  general  styles  of  ORM  are  Active  Record  and   Data  Mapper.    Active  Record  has  domain  objects  handle   their  own  persistence: Flavors of ORM user_record = User(name="ed", fullname="Ed Jones") user_record.save() user_record = User.query(name='ed').fetch() user_record.fullname = "Edward Jones" user_record.save()
  • 32. The  Data  Mapper  approach  tries  to  keep  the  details  of   persistence  separate  from  the  object  being  persisted. Flavors of ORM dbsession = start_session() user_record = User(name="ed", fullname="Ed Jones") dbsession.add(user_record) user_record = dbsession.query(User).filter(name='ed').first() user_record.fullname = "Edward Jones" dbsession.commit()
  • 33. ORMs  may  also  provide  different  configurational  patterns.   Most  use  an  "all-­‐at-­‐once",  or  declarative  style  where  class   and  table  information  is  together. Flavors of ORM # a hypothetical declarative system class User(ORMObject): tablename = 'user' name = String(length=50) fullname = String(length=100) class Address(ORMObject): tablename = 'address' email_address = String(length=100) user = many_to_one("User")
  • 34. A  less  common  style  keeps  the  declaration  of  domain   model  and  table  metadata  separate. Flavors of ORM # class is declared without any awareness of database class User(object): def __init__(self, name, username): self.name = name self.username = username # elsewhere, it's associated with a database table mapper( User, Table("user", metadata, Column("name", String(50)), Column("fullname", String(100)) ) )
  • 35. SQLAlchemy ORM • The  SQLAlchemy  ORM  is  essentially  a  data  mapper   style  ORM. • Modern  versions  use  declarative  configuration;  the   "domain  and  schema  separate"  configuration  model   is  present  underneath  this  layer. • The  ORM  builds  upon  SQLAlchemy  Core,  and  many   of  the  SQL  Expression  concepts  are  present  when   working  with  the  ORM  as  well.   • In  contrast  to  the  SQL  Expression  language,  which   presents  a  schema-­‐centric  view  of  data,  it  presents  a   domain-­‐model  centric  view  of  data.
  • 36. Key ORM Patterns • Unit  of  Work  -­‐  objects  are  maintained  by  a  system  that   tracks  changes  over  the  course  of  a  transaction,  and  flushes   pending  changes  periodically,  in  a  transparent  or  semi-­‐ transparent  manner • Identity  Map  -­‐  objects  are  tracked  by  their  primary  key   within  the  unit  of  work,  and  are  kept  unique  on  that  primary   key  identity. • Lazy  Loading  -­‐  Some  attributes  of  an  object  may  emit   additional  SQL  queries  when  they  are  accessed. • Eager  Loading  -­‐  Multiple  tables  are  queried  at  once  in  order   to  load  related  objects  and  collections. • Method  Chaining  -­‐  queries  are  composed  using  a  string  of   method  calls  which  each  return  a  new  query  object.
  • 38. Object Relational Mapping SQL Expressions Table Metadata, Reflection, DDL Engine, Connection, Transactions Thanks ! http://www.sqlalchemy.org @zzzeek