Skip to content

Instantly share code, notes, and snippets.

@espeed
Created April 27, 2012 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espeed/2512943 to your computer and use it in GitHub Desktop.
Save espeed/2512943 to your computer and use it in GitHub Desktop.
Jython 2.5.2 / Datomic Snippet (generates __getattribute__ error)
from java.io import Reader
from java.io import FileReader
from datomic import Entity
from datomic import Connection
from datomic import Database
from datomic import Peer
from datomic import TxReport
from datomic import Util
uri = "datomic:mem://seattle"
Peer.createDatabase(uri)
conn = Peer.connect(uri)
schema_rdr = FileReader("samples/seattle/seattle-schema.dtm")
schema_tx = Util.readAll(schema_rdr).get(0)
txResult = conn.transact(schema_tx).get()
schema_rdr.close()
print txResult
data_rdr = FileReader("samples/seattle/seattle-data0.dtm")
data_tx = Util.readAll(data_rdr).get(0)
txResult = conn.transact(data_tx).get()
data_rdr.close()
print txResult
try:
# This little hack works -- it only throws an error the first time
Peer.tempid("db.part/user")
except:
pass
# Create a community
temp_id = Peer.tempid("db.part/user")
m = Util.map(":db/id", temp_id, ":community/name", "Easton")
l = Util.list(m)
result = conn.transact(l).get()
print result
try:
db = conn.db()
except:
pass
db = conn.db()
# Get a community
try:
results = Peer.q("[:find ?id :where [?id :community/name \"Easton\"]]", db)
except:
pass
results = Peer.q("[:find ?id :where [?id :community/name \"Easton\"]]", db)
print results
# [[17592186045788]]
# Update a community
easton_id = (results.iterator().next()).get(0)
update_category_tx = Util.list(Util.map(":db/id", easton_id,
":community/category", "free stuff"))
txResult = conn.transact(update_category_tx).get()
print txResult
# Get
results = Peer.q("[:find ?c :where [?c :community/name]]", db)
id = (results.iterator().next()).get(0)
# This generates a "SystemError: __getattribute__ not found on type Db"
entity = db.entity(id)
#print entity.keySet()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment