please help with trouble. Problems with creating table in database (sqlite) and inserting data in it. Is can be encoding problems? Or likely something also like difference version packages etc?
with start build_database.py get this
...
INSERT INTO good (art, size, timestamp) VALUES (?, ?, ?)
INSERT INTO good (art, size, timestamp) VALUES (?, ?, ?)
...
anybody stuck with it(?
There are 3 files:
config.py:
import os
import connexion
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
basedir = os.path.abspath(os.path.dirname(__file__))
# Create the Connexion application instance
connex_app = connexion.App(__name__, specification_dir=basedir)
# Get the underlying Flask app instance
app = connex_app.app
# Configure the SQLAlchemy part of the app instance
app.config['SQLALCHEMY_ECHO'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'ec.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Create the SQLAlchemy db instance
db = SQLAlchemy(app)
# Initialize Marshmallow
ma = Marshmallow(app)
models.py
from datetime import datetime
from config import db, ma
class Good(db.Model):
_tablename__ = 'good'
good_id = db.Column(db.Integer, primary_key=True)
art = db.Column(db.String(32), index=True)
size = db.Column(db.String(32))
timestamp = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
class GoodSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = Good
load_instance = True
build_database.py
import os
from config import db
from models import Good
# Data to initialize database with
GOODS = [
{'art': 'art1', 'size': '42'},
{'art': 'art2', 'size': '44'},
]
# Delete database file if it exists currently
if os.path.exists('ec.db'):
os.remove('ec.db')
# Create the database
db.create_all()
# Iterate over the PEOPLE structure and populate the database
for good in GOODS:
p = Good(art=good['art'], size=good['size'])
db.session.add(p)
db.session.commit()

?is a placeholder, a marker for the driver that it should place an argument there. - Ilja Everilä