from basic import db, Puppy #creates all tables db.create_all() #creating puppy objects sam = Puppy('Sammy', 7) frank = Puppy('Frankie', 2) #Prints none because it has not been added to the DB print(sam.id) print(frank.id) #id are created once we add these entries to the DB db.session.add_all([sam, frank]) #save info to DB db.session.commit() #check id print(sam.id) print(frank.id)
from basic import db, Puppy # create my_puppy = Puppy('Rufus', 5) db.session.add(my_puppy) db.session.commit() frank = Puppy('Frankie', 4) db.session.add(frank) # read all_puppies = Puppy.query.all() # list of puppie obj in table print("PRINTING ALL PUPPIES") print(all_puppies) # select by id puppy_one = Puppy.query.get(1) print("PRINTING ONE PUPPY") print(puppy_one.name) # filters # produce some sql code puppy_frankie = Puppy.query.filter_by(name="Frankie") print("PRINTING ALL FRANKIES") print(puppy_frankie.all()) # Update first_puppy = Puppy.query.get(1) first_puppy.age = 10 db.session.add(first_puppy) db.session.commit()
from basic import db, Puppy ''' CREATE ''' rufus = Puppy('Rufus', 5) # db.session.add(rufus) # db.session.commit() ''' READ ''' filter_rufus = Puppy.query.filter_by(name='Rufus') # print(filter_rufus.all()) # get_third_pup = Puppy.query.get(3) # print(get_third_pup) ''' UPDATE ''' # get_third_pup.name = 'Spot' # get_third_pup.age = '6' # db.session.commit() ''' DELETE ''' # db.session.delete(get_third_pup) # db.session.commit() puppies = Puppy.query.all() print(puppies)
from basic import db,Puppy #Create my_puppy = Puppy('Rufus',5) db.session.add(my_puppy) db.session.commit() # Read all_puppies = Puppy.query.all() # list of puppy object in the table print(all_puppies) # Select by id puppy_one = Puppy.query.get(1) print(puppy_one.name) #Filters puppy_frankie = Puppy.query.filter_by(name = 'Frankie') print(puppy_frankie.all()) #Update first_puppy = Puppy.query.get(1) first_puppy.age = 10 db.session.add(first_puppy) db.session.commit() #Delete second_pup = Puppy.query.get(2)
from basic import db, Puppy #creat all tables db.create_all() sam = Puppy('SAMMY', 3) frank = Puppy('frankie', 4) db.session.add_all([sam, frank]) db.session.commit() print(sam.id) print(frank.id)
from basic import db, Puppy ####CREATE#### jhon=Puppy('jhonny',7) db.session.add(jhon) db.session.commit() ####READ#### all_puppies=Puppy.query.all() #list of puppy object print(all_puppies) #get by id id=8 puppy_one=Puppy.query.get(id) print(puppy_one.name) print(puppy_one) #Filters puppy_filtered=Puppy.query.filter_by(name= '%jhonny%') print(puppy_filtered.all()) #prints lists of all the query output ####UPDATE#### first_puppy=Puppy.query.get(1) first_puppy.age=9 db.session.add(first_puppy) db.session.commit() ####DELETE#### id =7
from basic import db, Puppy ## Create ## my_puppy = Puppy("Rufus", 5) db.session.add(my_puppy) db.session.commit() ## Read ## all_puppies = Puppy.query.all() #list of puppies objects in the table! print(all_puppies) # SELECT BY ID puppy_one = Puppy.query.get(1) print(puppy_one.name) # FILTERS puppy_frankie = Puppy.query.filter_by(name="Frankie") print(puppy_frankie.all()) ## UPDATE first_puppy = Puppy.query.get(1) first_puppy.age = 10 db.session.add(first_puppy) db.session.commit() ## DELETE second_puppy = Puppy.query.get(2)
from basic import db,Puppy import warnings warnings.filterwarnings('ignore') db.create_all() sai=Puppy('lucy',3) ram=Puppy('mike',5) print(sai.id) print(ram.id) db.session.add_all([sai,ram]) db.session.commit() print(sai.id) print(ram.id)
from basic import db, Puppy ## create my_puppy = Puppy('Rufus', 10) db.session.add(my_puppy) db.session.commit() ## Reading all_puppies = Puppy.query.all() print(all_puppies) # select by id puppy_one = Puppy.query.get(1) print(puppy_one.name) # filters puppy_frankie = Puppy.query.filter_by(name='Frankie') print(puppy_frankie.all()) ## Update first_puppy = Puppy.query.get(1) first_puppy.age = 20 db.session.add(first_puppy) db.session.commit() print(all_puppies) ## Delete
from basic import db, Puppy ########## create my_puppy = Puppy('Rufus', 10) db.session.add(my_puppy) db.session.commit() my_puppy = Puppy('Gogo', 1) db.session.add(my_puppy) db.session.commit() ########## read # This returns a list of the puppy objects in the table all_puppies = Puppy.query.all() print(all_puppies) # select by id puppy_one = Puppy.query.get(1) print(puppy_one.name) puppy_three = Puppy.query.get(3) print(puppy_three.name) # Filters puppy_sam = Puppy.query.filter_by(name='Sammy') # Returns list print(puppy_sam.all()) print('\n') # produce some sql code for us puppy_age_one = Puppy.query.filter_by(age=10) # this prints out the list of all the puppies where the name is Frankie
from basic import db,Puppy #creates all the tables model --> db table db.create_all() sam=Puppy('samm',3) frank=Puppy('frankk',4) db.session.add_all([sam,frank]) db.session.commit() print(sam.id) print(frank.id)
from basic import db, Puppy ##CREATE my_puppy = Puppy('Rufus', 5) my_puppy1 = Puppy('Halima', 4) db.session.add_all([my_puppy, my_puppy1]) db.session.commit() #READ all_puppies = Puppy.query.all() #list of all objects in the table print(all_puppies) #SELECT by ID puppy_one = Puppy.query.get(1) print(puppy_one.name) #FILTERS puppy_frankie = Puppy.query.filter_by(name='Frankie') print(puppy_frankie.all()) ###UPDATE first_puppy = Puppy.query.get(1) first_puppy.age = 10 db.session.add(first_puppy) db.session.commit()
from basic import db, Puppy # creates all the tables # takes classes and converts them into tables db.create_all() sam = Puppy('Sammy', 3) frank = Puppy('Frankie', 4) miles = Puppy('Miles', 10) # These will say none because they are not in the database yet # They don't have any ids print(sam.id) print(frank.id) print(miles.id) # Add these two objects to the database db.session.add_all([sam, frank, miles]) # commit changes db.session.commit() print(sam.id) print(frank.id) print(miles.id)
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)
from basic import db, Puppy # Creates all the python Models --> DB Table db.create_all() tuna = Puppy('Tuna', 9) toast = Puppy('Toaster', 14) # None # None print(tuna.id) print(toast.id) # Adding all objects to the database. db.session.add_all([tuna, toast]) db.session.commit() print(tuna.id) print(toast.id)
from basic import db, Puppy peter = Puppy('tomii', 13) db.session.add_all([peter]) db.session.commit() print(peter) #reading from database print(Puppy.query.all()) # select by id print(Puppy.query.get(1)) #filter puppy_frank = Puppy.query.filter_by(name='frankie') print(puppy_frank.all()) #####update pup = Puppy.query.get(1) pup.age = 10 db.session.add(pup) db.session.commit()
from basic import db, Puppy # Creates all the tables model --> db table db.create_all() sam = Puppy("Sammy", 3, "german shephard") frank = Puppy("Frankie", 4, "bulldog") db.session.add_all([sam, frank]) db.session.commit() print(sam) print(frank)
from basic import db, Puppy db.create_all() sam = Puppy('Sam', 3) frank = Puppy('Frank', 4) db.session.add_all([sam, frank]) db.session.commit() puppies = Puppy.query.all() print(all_puppies)
from basic import db, Puppy # Crea todas las tablas db.create_all() sam = Puppy('Sammy', 3, 'Lab') frank = Puppy('Frankie', 4, 'Shepard') # Podemos agregarlo a la db con una sola línea # Para ello, le pasamos por parámetro una lista. db.session.add_all([sam, frank]) # Guardamos los objetos db.session.commit() # Obtenemos todos los elementos de tipo Puppy # de la tabla puppy all_puppies = Puppy.query.all() print(all_puppies) # Podemos filtrar por una columna de la tabla # Siempre dará como resultado una lista. puppy_frankie = Puppy.query.filter_by(name='Frankie') ########## UPDATE # Recuperamos el primer elemento first_puppy = Puppy.query.get(1)
from basic import db,Puppy #creates my_obj=Puppy('rufus',5) db.session.add(my_obj) db.session.commit() #Read All_puppies=Puppy.query.all() print(All_puppies) #Select by id pup_1=Puppy.query.get(1) print(pup_1) #filters pup_frank = Puppy.query.filter_by(name='frankk') print(pup_frank.all()) #update first_puppy=Puppy.query.get(1) first_puppy.age=10 db.session.add(first_puppy) db.session.commit() #Delete second_pup=Puppy.query.get(2) db.session.delete(second_pup) db.session.commit() All_puppies=Puppy.query.all()
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)
from basic import db,Puppy my_puppy = Puppy('rufus',12) db.session.add(my_puppy) db.session.commit() print("showing all data") all_puppies=Puppy.query.all() print(all_puppies) print("selecting by id") one_puppy=Puppy.query.get(1) print(one_puppy.name) print("using filters") puppy_lucy=Puppy.query.filter_by(name='lucy') print(puppy_lucy.all()) print("update") first_puppy=Puppy.query.get(1) first_puppy.age=10 db.session.add(first_puppy) db.session.commit() print("showing all data") all_puppies=Puppy.query.all() print(all_puppies) print("delete") second_puppy=Puppy.query.get(2) db.session.delete(second_puppy)
from basic import db, Puppy ## Create ## mypuppy = Puppy('Rufus', 5) db.session.add(mypuppy) db.session.commit() ## READ ## all_puppies = Puppy.query.all() print(all_puppies) #select by ID puppy_one = Puppy.query.get(1) print(puppy_one.name) #Filters #by name puppy_frankie = Puppy.query.filter_by(name='Frankie') print(puppy_frankie.all()) #Update first_puppy = Puppy.query.get(1) first_puppy.age = 10 db.session.add(first_puppy) db.session.commit() ##Delete # second_puppy = Puppy.query.get(2) # db.session.delete(second_puppy) # db.session.commit()
from basic import db,Puppy #Creates all the Table Models db.create_all() sam=Puppy('sams',3) frank=Puppy('franky',4) print(sam.id,frank.id) db.session.add_all([sam,frank]) db.session.commit() print(sam.id,frank.id)