Closed Wanhenri closed 4 years ago
In the first moment, I was going to use an SQLite3 library but prefer to use the Flask-SQLAlchemy or sqlalchemy library
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///conexaosql.db'
db = SQLAlchemy(app)
class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20))
code = db.Column(db.String(20))
price = db.Column(db.Float(precision='4,2'), nullable=True)
def __init__(self,name,code,price):
self.name = name
self.code = code
self.price = price
class Vendor(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20))
cnpj = db.Column(db.String(20))
city = db.Column(db.String(20))
def __init__(self,name, cnpj, city):
self.name = name
self.cnpj = cnpj
self.city = city
db.create_all()
The vendor record need to have these fields: ● Id (self generated, surrogate key) ● Name (required) ● CNPJ (required, this value is unique, ie, you can only have one record given a single CNPJ) ● City
The product record need to have these fields: ● Id (self generated, surrogate key) ● Name (required) ● Code (required) ● Price