import mysql.connector

import click
from flask import current_app, g
from flask.cli import with_appcontext
from .schema  import instructions

from flask import Flask
from flask_sqlalchemy import flask_sqlalchemy

app  = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']= 'mysql+pymysql://root:Jj-1026596645@localhost/flaskmysql'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False

db = SQLAlchemy(app)
ma= Marsmallow(app)

class Task(db,Model):
    id= db.Column(db.Integer, db.AUTO_INCREMENT, priary_key=True)
    



# def get_db():
#     if 'db' not in g:
#         g.db = mysql.connector.connect(
#             host = current_app.config[' DATABASE_HOST'],
#              user=current_app.config['DATABASE_USER'],
#              password=current_app.config['DATABASE_PASSWORD'],
#              database=current_app.config['DATABASE']
            
#         )
#         g.c = g.db.cursor(dictionary=True)
#     return g.db, g.c

# def close_db(e=None):
#     db = g.pop('db', None)
#     if db is not None:
#         db.close()

# def init_db():
#     db, c = get_db()

#     for i in instructions:
#         c.execute(i)

#     db.commit()

# @click.command('init-db')
# @with_appcontext


# def init_db_command():
#     init_db()
#     click.echo("Base de datos inicializada")


# def init_app(app):
#     app.teardown_appcontext(close_db)
#     app.cli.add_command(init_db_command)