summaryrefslogtreecommitdiff
path: root/examples/elementtree/pickle.py
diff options
context:
space:
mode:
authorVraj Mohan <radhakrishnan.vrajmohan@gsa.gov>2019-01-16 15:36:54 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-01-16 20:21:48 -0500
commit0717ce9d1dc28b67b4568351f4e98e59a831b1f1 (patch)
tree6847888b4cab8d7dbf3554241d266303215d7a15 /examples/elementtree/pickle.py
parent313be7c78db070169bd863948f922c74871d7000 (diff)
downloadsqlalchemy-0717ce9d1dc28b67b4568351f4e98e59a831b1f1.tar.gz
Reinstate elementtree example
Partially fixes sqlalchemy/sqlalchemy#4426. Closes: #4441 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4441 Pull-request-sha: ed90f3b77c2d0f4cc2cd54f40f5af29b489977d2 Change-Id: Ic32e5d8020073da055b12a6aeb61e698a97dc504
Diffstat (limited to 'examples/elementtree/pickle.py')
-rw-r--r--examples/elementtree/pickle.py79
1 files changed, 0 insertions, 79 deletions
diff --git a/examples/elementtree/pickle.py b/examples/elementtree/pickle.py
deleted file mode 100644
index ca2c65504..000000000
--- a/examples/elementtree/pickle.py
+++ /dev/null
@@ -1,79 +0,0 @@
-"""
-illustrates a quick and dirty way to persist an XML document expressed using
-ElementTree and pickle.
-
-This is a trivial example using PickleType to marshal/unmarshal the ElementTree
-document into a binary column. Compare to explicit.py which stores the
-individual components of the ElementTree structure in distinct rows using two
-additional mapped entities. Note that the usage of both styles of persistence
-are identical, as is the structure of the main Document class.
-
-"""
-
-import os
-import sys
-from xml.etree import ElementTree
-
-from sqlalchemy import Column
-from sqlalchemy import create_engine
-from sqlalchemy import Integer
-from sqlalchemy import MetaData
-from sqlalchemy import PickleType
-from sqlalchemy import String
-from sqlalchemy import Table
-from sqlalchemy.orm import mapper
-from sqlalchemy.orm import Session
-
-
-e = create_engine("sqlite://")
-meta = MetaData()
-
-# setup a comparator for the PickleType since it's a mutable
-# element.
-
-
-def are_elements_equal(x, y):
- return x == y
-
-
-# stores a top level record of an XML document.
-# the "element" column will store the ElementTree document as a BLOB.
-documents = Table(
- "documents",
- meta,
- Column("document_id", Integer, primary_key=True),
- Column("filename", String(30), unique=True),
- Column("element", PickleType(comparator=are_elements_equal)),
-)
-
-meta.create_all(e)
-
-# our document class. contains a string name,
-# and the ElementTree root element.
-
-
-class Document(object):
- def __init__(self, name, element):
- self.filename = name
- self.element = element
-
-
-# setup mapper.
-mapper(Document, documents)
-
-# time to test !
-
-# get ElementTree document
-filename = os.path.join(os.path.dirname(__file__), "test.xml")
-doc = ElementTree.parse(filename)
-
-# save to DB
-session = Session(e)
-session.add(Document("test.xml", doc))
-session.commit()
-
-# restore
-document = session.query(Document).filter_by(filename="test.xml").first()
-
-# print
-document.element.write(sys.stdout)