Commits

Antonio Cuni committed 9e490f9 Draft

start to explain the elixir import hack

Comments (0)

Files changed (4)

+from elixir import Entity, Field, Unicode, Integer, metadata, setup_all, create_all
+
+metadata.bind = "sqlite:///db.sqlite"
+
+class User(Entity):
+    name = Field(Unicode)
+    age = Field(Integer)
+
+
+if __name__ == '__main__':
+    setup_all()
+    create_all()
+import sqlalchemy
+from elixir import (Entity, Field, Unicode, Integer,
+                    setup_entities, GlobalEntityCollection)
+
+__session__ = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker())
+__metadata__ = sqlalchemy.MetaData(bind="sqlite:///db.sqlite")
+__collection__ = GlobalEntityCollection()
+
+
+class User(Entity):
+    name = Field(Unicode)
+    age = Field(Integer)
+
+
+if __name__ == '__main__':
+    setup_entities(__collection__)
+    __metadata__.create_all()
+

talk/stylesheet.latex

 \usetheme{Boadilla}
+\usecolortheme{whale}
 \setbeamercovered{transparent}
 \setbeamertemplate{navigation symbols}{}
 
 * Cons
 
   - None :-)
+
+
+Problem #4: implicit global state
+===================================
+
+* ``elixir``
+
+  - declarative layer on top of SQLAlchemy
+
+  - (precursor of ``sqlalchemy.declarative``)
+
+|pause|
+
+|scriptsize|
+|example<| |small| model.py |end_small| |>|
+
+.. sourcecode:: python
+
+    from elixir import (Entity, Field, Unicode, Integer, 
+                        metadata, setup_all, create_all)
+
+    metadata.bind = "sqlite:///db.sqlite"
+
+    class User(Entity):
+        name = Field(Unicode)
+        age = Field(Integer)
+
+
+    setup_all()
+    create_all()
+    # ...
+
+|end_example|
+|end_scriptsize|
+
+Global state
+=============
+
+* Global state is evil
+
+  - that's it
+
+  - implicit is even worse
+
+|pause|
+
+* Hard to test
+
+  - no isolation for tests
+
+  - persistent side effects (e.g. DB)
+
+|pause|
+
+* Goal
+
+  - multiple, isolated, independent DBs
+
+  - one DB per test (or group of tests)
+
+A step forward (1)
+==================
+
+|scriptsize|
+|example<| |small| model.py |end_small| |>|
+
+.. sourcecode:: python
+
+    import sqlalchemy
+    from elixir import (Entity, Field, Unicode, Integer,
+                        setup_entities, GlobalEntityCollection)
+
+    __session__ = sqlalchemy.orm.scoped_session(
+                        sqlalchemy.orm.sessionmaker())
+    __metadata__ = sqlalchemy.MetaData(bind="sqlite:///db.sqlite")
+    __collection__ = GlobalEntityCollection()
+
+
+    class User(Entity):
+        name = Field(Unicode)
+        age = Field(Integer)
+
+    if __name__ == '__main__':
+        setup_entities(__collection__)
+        __metadata__.create_all()
+
+|end_example|
+|end_scriptsize|
+
+A step forward (2)
+==================
+
+* Still global state
+
+  - but explicit
+
+* ...