Пример #1
0
from basic import db, Puppy

# creates all the tables model to an actual database table
db.create_all()
sam = Puppy('Sammy', 3)
frank = Puppy('Frankie', 5)

print(sam.id)
print(frank.id)

db.session.add_all([sam, frank])

db.session.commit()
print(sam.id)
print(frank.id)





Пример #2
0
from basic import db, Puppy

db.create_all()  #creates akk the tables(models)

sam = Puppy('Sammy', 3)
frank = Puppy('Franky', 4)

print(sam.id)  #it will print 'None'
print(frank.id)  #it will print 'None'

db.session.add_all([sam, frank])
#or you can add each object indivdually to the DB
#db.session.add(sam)
#db.session.add(frank)

db.session.commit()
print(sam.id)
print(frank.id)
Пример #3
0
#-------------------------------------------------------------------------------
# CRUD Script - You can not use this script twice
#-------------------------------------------------------------------------------
from basic import db, DragonBall

#-------------------------------------------------------------------------------
# Setup fo DATABASE
#-------------------------------------------------------------------------------

db.create_all()  # Create all the tables model --> Db Table

goku = DragonBall('Goku', '150', 'Saiyajin')
kr = DragonBall('Krillin', '40', 'Humano')

db.session.add_all([goku, kr])  # Adding
db.session.commit()  # Escribir en base de datos
Пример #4
0
from basic import db, Kitty

db.create_all(
)  #Setting up the database. Creates all the table models. Model class to db tables

charlie = Kitty('Charlie', 4)

ginger = Kitty('Ginger', 3)

# The below will print none since these entries have not yet been added to the database

print(charlie.id)

print(ginger.id)

db.session.add_all([charlie,
                    ginger])  # Adding a list of objects into the table

db.session.commit()  # Saves the changes to the databse

print(charlie.id)

print(ginger.id)