Exemple #1
0
m = Manager()
conf = ConnectionConfiguration(user="******",
                               password="******",
                               database="postgres")
m.connect(conf)
m.create_tables()

# EXAMPLE 1 ######################## simple insert, update, delete ##################################

monkey = Monkey()
monkey.animal_id = 1
monkey.mammal_type = 'humanoid'
monkey.monkey_name = 'Ham'
monkey.monkey_weight = 20.5

m.insert(monkey)
monkey.monkey_weight = 30.9
m.update(monkey)

find = m.find_by_id(Monkey(), 1)
print("\nI found a monkey!\nMammal type:", find.mammal_type, "Name:",
      find.monkey_name, "Weight:", find.monkey_weight, "\n")

m.delete(monkey)

# EXAMPLE 2 ######################## simple multi insert #############################################

f1 = Footballer()
f2 = Footballer()
m1 = Match()
m2 = Match()
actor2.id = 2
actor2.name = "name2"
actor2.film_fk = [film1, film2]

film1.id = 1
film1.title = "title1"
film1.actor_fk = [actor1, actor2]

film2.id = 2
film2.title = "title2"
film2.actor_fk = [actor1, actor2]

# EXAMPLE 1 ######################## simple many to one relation with update ##################################

m.insert(p)
m.insert(a1)
m.insert(a2)

p._first_name = "changedFK"
m.update(p)

to_update = Person()
to_update = m.find_by_id(to_update, "changedFK")
print("\nFound record:", to_update._first_name, to_update._second_name, "\n")

to_update._second_name = "From findby"
m.update(to_update)

m.delete(a1)
m.delete(a2)