In [1]:
from datomic import *
In [2]:
# Connect to the database
db = DB('localhost', 8080, 'free', 'tvdata')
In [3]:
# Review the database information
db.info()
Out[3]:
In [4]:
# Start a new transaction
tx = db.tx()
In [5]:
# Add a person to our database
person = tx.add("person/", {'name': "Wanda Sykes"})
In [6]:
# Demonstrate that our person has a temp id
# In Datomic, all temp ids are negative
print(person)
In [7]:
# Commit our transaction
tx.execute()
Out[7]:
In [8]:
# Retrieve our person, post commit
db.e(person)
Out[8]:
In [9]:
# List all the people in our database
db.q('[:find ?p :where [_ :person/name ?p]]')
Out[9]:
In [10]:
# Get the name of our newly added person
db.e(person).get('person/name')
Out[10]:
In [11]:
# Retract the person with the name 'Wanda Sykes' from our database
db.retract(person, 'person/name', 'Wanda Sykes')
Out[11]:
In [12]:
# Get the list of all people in our database, post retraction
people = db.q('[:find ?p :where [_ :person/name ?p]]')
In [13]:
# "people" is just a list of lists of people, get its length
len(people)
Out[13]:
In [14]:
# pull the names out into a new list "name_list"
name_list = [name[0] for name in people]
In [15]:
name_list
Out[15]:
In [16]:
# filter out names that contain the letter "e"
filter(lambda x: x.find('e') > -1, name_list)
Out[16]:
In [ ]: