Commits

Pierre Carbonnelle committed 49a2279

use create_atoms() in sqlalchemy example

Comments (0)

Files changed (1)

pyDatalog/examples/SQLAlchemy.py

 session.commit()
 
 """ 4. Query the objects using the datalog engine """
+pyDatalog.create_atoms('X, Y, N, lowest')
+
 # the following python statements implicitly use the datalog clauses in the class definition
 
 # What is the salary class of John ?
 # what is the total salary of the employees of John ?
 # note : it is better to place aggregation clauses in the class definition 
 Mary.salary = 6400 # queries use the latest, in-session, data
-pyDatalog.load("(Employee.budget[X] == sum(N, for_each=Y)) <= (Employee.indirect_manager(Y, X)) & (Employee.salary[Y]==N)")
+(Employee.budget[X] == _sum(N, for_each=Y)) <= (Employee.indirect_manager(Y, X)) & (Employee.salary[Y]==N)
 Employee.budget[John]==X
 print(X) # prints [12300]
 
 # who has the lowest salary ?
-pyDatalog.load("(lowest[1] == min(X, order_by=N)) <= (Employee.salary[X]==N)")
+(lowest[1] == _min(X, order_by=N)) <= (Employee.salary[X]==N)
 # must use ask() because inline queries cannot use unprefixed literals 
-print(pyDatalog.ask("lowest[1]==X")) # prints set([(1, Employee: Sam)])
+print(lowest[1]==X) # prints [(Employee: Sam,)]