How AI, OpenAI, and ChatGPT impact business and software.
ZODB, the Zope Object Database (May 2003)
1. ZODB
The Zope Object Database
An introduction to the open source object database, by
Kiran Jonnalagadda <jace@pobox.com>
http://jace.seacrow.com/
2. Agenda
Where relational databases are unwieldy
The object database methodology
A brief introduction to Python
Mechanics of ZODB
Limitations
Resources
3. Relational Database Records
Record 1
Record 2
...
First Name
Atul
Kiran
...
Last Name
Chitnis
Age
41
24
...
Phone No.
344 0397
658 2921
...
Jonnalagadda ...
Individual Record Is Not Extensible
Extensible
Field
4. Issues with Relational DBs
Can’t store multiple values in a single field
Can’t add extra fields to individual records
Solved by adding extra relational tables
With complex data, this gets unmanageable
Developer time is wasted writing a database
interaction layer
6. Object Concepts
An object oriented database stores objects
instead of database records
Objects contain variables (data) and methods
to act on these variables; may be inherited
Objects are usually organised hierarchically
Most object databases are bound to a specific
language because each language implements
OOP differently
8. Why Python?
Python is a dynamic
typed and a strong
typed language
Python is dynamic:
everything can be
modified at runtime. Class
members, base
classes, whatever
10. What ZODB is Not
Not a relational database
No SQL support
No security model
No query interface:
Objects must be accessed via container
A separate search engine is available
12. Really Simple Usage
All classes must be derived from the
“Persistent” base class provided by ZODB
At the start of your program, open a ZODB
connection
Commit the transaction periodically
That is all!
Code need not be ZODB aware
13. Example Code
# Necessary imports
from ZODB import FileStorage, DB
from Persistence import Persistent
# Connect to a database
storage = FileStorage.FileStorage('/tmp/test-filestorage.fs')
db = DB(storage)
conn = db.open()
# Get the root of the database
dbroot = conn.root()
# Defining user classes
class UserDataClass(Persistent):
pass
# Commit or abort after making a change
get_transaction().commit()
get_transaction().abort()
14. Remote Storage: ZEO
ZEO is Zope Enterprise Objects
One ZEO serves multiple ZODB clients
Databases can be mounted on each other, just
like file systems
No replicated storage yet
15. Available ZODB Storages
FileStorage (standard)
The entire database is stored in a single file
DirectoryStorage
Each object is stored as a separate file
BerkeleyDB Storage
The database is stored in BerkeleyDB
ClientStorage
Database is stored in a remote ZEO database
16. Limitations
Only available via Python
Transparency is sometimes undesirable
Cannot detect changes in objects not derived
from the Persistent base class, like a list or
dictionary
Programmer has to flag such objects as dirty
ZEO is optimised for heavy reads, not writes