sqlalchemy

SQL Alchemy, how to insert data into two tables and reference foreign key?

点点圈 提交于 2021-02-08 07:34:21
问题 I am inserting a list of python dictionaries into a Postgres database using SQL Alchemy (via Flask_sqlalchemy). One of the tables is a list of all unique items (table 1), while the second is a time series of data related to an item (table2). In essence, I want to insert any new row (with unique hash) in to table 1, then insert it's data to table 2. If it already exists in table 1, just insert the "child" in table 2 referencing the entry in table 1. This is one item in the list, the list has a

When connecting to multiple databases, do I need multiple SQLAlchemy Metadata, Base, or Session objects?

青春壹個敷衍的年華 提交于 2021-02-08 07:33:30
问题 I'm writing a SQLAlchemy app that needs to connect to a PostgreSQL database and a MySQL database. Basically I'm loading the data from an existing MySQL database, doing some transforms on it, and then saving it in PostgreSQL. I am managing the PostgreSQL schema using SQLAlchemy's declarative base . The MySQL database already exists, and I am accessing the schema via SQLAlchemy's reflection. Both have very different schemas. I know I need dedicated engines for each database, but I'm unclear on

Flask, Python 3, error: “Additional arguments should be named”

落花浮王杯 提交于 2021-02-07 19:03:55
问题 Problem: i get an errorusig flask, and i am following a tutorial(using flash, i am a meh level python programmer(i get the basics)), so i don't understand why or what is wrong with this, so if you don't mind explaining it or adding a link to a place were it is explained... the error(i don't know what is important, sorry): C:\Users\name\Desktop\Eeverything on this computer\GCSE\Computer Science\free-style\organised\website>python flaskblog.py C:\Users\name\Anaconda3\lib\site-packages\flask

Flask, Python 3, error: “Additional arguments should be named”

孤人 提交于 2021-02-07 19:01:45
问题 Problem: i get an errorusig flask, and i am following a tutorial(using flash, i am a meh level python programmer(i get the basics)), so i don't understand why or what is wrong with this, so if you don't mind explaining it or adding a link to a place were it is explained... the error(i don't know what is important, sorry): C:\Users\name\Desktop\Eeverything on this computer\GCSE\Computer Science\free-style\organised\website>python flaskblog.py C:\Users\name\Anaconda3\lib\site-packages\flask

set value for a column with dynamic name in python sqlalchemy

你说的曾经没有我的故事 提交于 2021-02-07 18:42:47
问题 I have the following defined table in Python sqlalchemy: class entry(Base): summary = Column(String(10000)) content = Column(String(10000)) description = Column(String(10000)) And I basically want to do the following: a = entry() for col in ['summary', 'content', 'description']: a[col] = get_value(col) But I got the following error: TypeError: 'entry' object has no attribute '__getitem__' So I guess I cannot treat a as a dict . Looking through sqlalchemy document, I didn't figure out a way to

How to verify SqlAlchemy engine object

ぃ、小莉子 提交于 2021-02-07 11:23:09
问题 I can declare engine object with the invalid username, password or address and get no exception or error: from sqlalchemy import create_engine engine = create_engine('mysql://nouser:nopassword@123.456.789') print engine it prints likes it is a valid engine object: Engine(mysql://nouser:***@123.456.789) What would be a common way to verify (to check) if the engine object is valid or if it is "connectable" to db? 回答1: Question: How to verify if the engine object is "connectable"? From the (DOCs

SQLAlchemy: filtering count in many-to-many relationship query

大城市里の小女人 提交于 2021-02-07 10:20:35
问题 In my Flask app, there is a many-to-many relationship between Documents and Tokens: DocTokens = db.Table( 'DocTokens', db.Column('token_id', db.Integer, db.ForeignKey('Token.id')), db.Column('document_id', db.Integer, db.ForeignKey('Document.id')), ) class Token(db.Model): __tablename__ = 'Token' id = db.Column(db.Integer, primary_key=True) ... is_gold = db.Column(db.Boolean, default=None) class Document(db.Model): __tablename__ = 'Document' id = db.Column(db.Integer, primary_key=True) ...

Flask-SQLAlchemy database engine returns table names, but the table keys in metadata are empty

倾然丶 夕夏残阳落幕 提交于 2021-02-07 09:25:24
问题 I am connected to a MS SQL Server. The following returns all the table names in the database: app.config.from_object('config') db = SQLAlchemy(app) db.engine.table_names() However, this doesn't: db.metadata.tables.keys() // returns: dict_keys([]) Similarly, this doesn't work: db.table('dbo.users').primary_key // returns: ColumnSet([]) However, I am able to execute SQL queries. What would be the problem? 回答1: Engine.table_names gives you a list of available table names from the database.

Superset for Clickhouse in docker with SQLAlchemy

扶醉桌前 提交于 2021-02-07 09:13:17
问题 I'm trying to setup Apache Superset for Clickhouse. My understanding so far is that I need to install SQLAlchemy for Clickhouse https://github.com/xzkostyan/clickhouse-sqlalchemy I'm in Ubuntu 16.04 LTS, and using the Docker vanilla version of Clickhouse and of Superset: https://store.docker.com/community/images/yandex/clickhouse-server https://hub.docker.com/r/amancevice/superset/ without special settings Any idea how I can bridge the two docker containers with clickhouse-sqlalchemy ? Where

Superset for Clickhouse in docker with SQLAlchemy

旧城冷巷雨未停 提交于 2021-02-07 09:12:15
问题 I'm trying to setup Apache Superset for Clickhouse. My understanding so far is that I need to install SQLAlchemy for Clickhouse https://github.com/xzkostyan/clickhouse-sqlalchemy I'm in Ubuntu 16.04 LTS, and using the Docker vanilla version of Clickhouse and of Superset: https://store.docker.com/community/images/yandex/clickhouse-server https://hub.docker.com/r/amancevice/superset/ without special settings Any idea how I can bridge the two docker containers with clickhouse-sqlalchemy ? Where