Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…me-api into dev
  • Loading branch information
FabianNorbertoEscobar committed Jul 7, 2023
2 parents 549209f + 02ffa07 commit bc08d2d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ def create_tables():
''')
conn.commit()

print("Creando tabla compra si no existe...")
cursor.execute('''
CREATE TABLE IF NOT EXISTS compra (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username INT NOT NULL,
precio REAL NOT NULL,
fecha_hora TIMESTAMP NOT NULL
);
''')
conn.commit()

print("Creando tabla compra_item si no existe...")
cursor.execute('''
CREATE TABLE IF NOT EXISTS compra_item (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id_compra INTEGER NOT NULL,
id_producto INTEGER NOT NULL,
cantidad INTEGER NOT NULL,
precio_unitario REAL NOT NULL,
FOREIGN KEY (id_compra) REFERENCES compra (id),
FOREIGN KEY (id_producto) REFERENCES producto (id)
);
''')
conn.commit()

print("Fin creacion de tablas...")

cursor.close()
Expand All @@ -112,6 +137,8 @@ def populate_tables():
DELETE FROM animal;
DELETE FROM persona;
DELETE FROM adopcion;
DELETE FROM compra;
DELETE FROM compra_item;
''')
conn.commit()
print("Fin de vaciado de tablas")
Expand Down Expand Up @@ -266,6 +293,18 @@ def populate_tables():
''')
conn.commit()

print("Insertando en tabla compra...")
cursor.executescript('''
''')
conn.commit()

print("Insertando en tabla compra_item...")
cursor.executescript('''
''')
conn.commit()

print("Fin insercion de registros de ejemplo...")

cursor.close()
Expand Down

0 comments on commit bc08d2d

Please sign in to comment.