Buenas, una consulta. Estoy creando un pequeño programa en python (mi primer programa) y necesito crear una base de datos usando sqlalchemy y sqlite

El programa debe guardar el stock de 6 variedades de orégano de un galpón. Las clases son: Orégano y Depósito. Los métodos son: comprar y vender. El stock debería mostrarse automáticamente al modificar el stock usando esos dos métodos

Как передать дату в базу используя SQLAlchemy

db = SQLAlchemy(app)  class Example(db.Model):     __tablename__ = "example"  id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DATE) 

Какое значение необходимо передать в Example.date, чтобы добавить указанную(не текущую) дату. Например 2018-04-01

SQLAlchemy with Plain Old Python Objects (POPO)

In SQLAlchemy class models are of data type Column which contain metadata about the table in the database. Such as:

id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)

When I used Hibernate, we had DTO classes (aka POJO’s) which contained only the variables required to represent the object.

QUESTION: Should this pattern be used with SQLAlchemy? The DTO objects will be passed and eventually serialized in my API.

SQLAlchemy with Plain Old Python Objects (POPO)

In SQLAlchemy class models are of data type Column which contain metadata about the table in the database. Such as:

id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)

When I used Hibernate, we had DTO classes (aka POJO’s) which contained only the variables required to represent the object.

QUESTION: Should this pattern be used with SQLAlchemy? The DTO objects will be passed and eventually serialized in my API.

SQL Server Bulk Insert vs Python SQLAlchemy Bulk Operations

Apologies if this belongs in a different StackExchange forum.

I’m being tasked with building out an ETL process and the current adhoc ETL Python script is using SQLAlchemy to do bulk insert operations into a SQL Server hosted on AWS via RDS. My understanding is that RDS doesn’t support Bulk Insert so I’m trying to understand what the difference is and how does one work and not another. Can anyone help explain?

SQLAlchemy expression for timestamptz at a particular timezone

Given a PostgreSQL timestamptz, I’d like to extract the date in a particular timezone. The SQL expression is straightforward:

SELECT date_trunc('day', column_name AS TIME ZONE 'my/zone')::date FROM table_name 

How do I represent this as a SQLAlchemy expression? I can get the date_trunc function using session.query(func.date_trunc('day', table.column)), but how I add the AS TIME ZONE bit?

SQLAlchemy Insert executemany Func

I am trying to bulk insert a list of dicts into a MySQL database via SQLAlchemy. Inside the list each dict has time and temperature. The time values are as an ISO time string. I am trying to have MySQL use the STR_TO_DATE function on the way in to create datetime objects to store to the database.

I have sucessfully had this working via insert().values({‘time’:func.STR_TO_DATE(row.time, date_str), ‘temp’ = row.temp})

Not sure how to go about getting this to work by binding a parameter to a single input value that can call the STR_TO_DATE so data can be inserted via a list of dicts.

Pasar una tabla desde SqlAlchemy a un html flask

mi problema es este, la cosa es que tengo una tabla con asignaturas como puede ser álgebra , calculo , etc y tengo hacer elegir al usuario una de estas pero no se como sacar todos los nombres de la tabla para pasarlo a una lista y enviarlo al html para después de eso mostrar un input de tipo radio y elija una de las asignaturas.

Codigo flask:

@app.route('/evaluacion', methods=['GET', 'POST']) def evaluacion():     if request.method == 'POST':         asignatura = request.form['materia']         return redirect( url_for('profesor', asignatura=asignatura ))      ramos = Asignatura.query.filter_by().all()     return render_template('ramos.html', ramos = ramos ) 

Codigo html:

   <form action="http://localhost:5000/evaluacion">         {% for {name} in ramos %}             name <input type="radio" name="asignatura" value="{{ name }}">         {% endfor %}     </form> 

La verdad tampoco se si la parte del html esta bien, ya que soy un completo noob en el tema. Gracias de antemano.