Questions tagged [sqlalchemy-utils]

36 questions
6
votes
5 answers

How to use SQLAlchemy Utils in a SQLAlchemy model

I'm trying to create a user model that uses UUID as primary key: from src.db import db # SQLAlchemy instance import sqlalchemy_utils import uuid class User(db.Model): __tablename__ = 'user' id =…
user7075574
6
votes
1 answer

python postgresql create database and populate table from pandas dataframe

I am quite new to Python and also very new to using postgresql, so please forgive me if this is something basic (which I - so far - have failed to achieve). I'm trying to write a python code that: creates a new database (testdb) reads a csv file…
qstnr
  • 61
  • 1
  • 5
4
votes
0 answers

SQLAlchemy-utils: create view "if not exists"

When I use the create_view () method of the sqlalchemy-utils module, everything works just fine the first time I run my script. However, every time after that first call, I encounter this error : sqlalchemy.exc.OperationalError:…
3
votes
1 answer

Querying Sqlalchemy-utils EncrytedType directly as an SQL query

I have a 'User' table with the email as encrypted type, class AllUser(db.Model): id = db.Column(db.Integer, autoincrement=True, primary_key=True, index=True) email = db.Column(EncryptedType(db.String(200), KEY), primary_key=True,…
SAK
  • 169
  • 2
  • 11
3
votes
0 answers

SQLAlchemy / PostgreSQL cannot determine type of parameter jsonb[]

I'm a first time user of SQLAlchemy using it with PostgreSQL, FastAPI and databases library. I'm having trouble converting a working raw query to the SQLAlchemy approach in particular on determening the column type as jsonb[] and including it in a…
2
votes
0 answers

SQLAlchemy error: Data modification failed on system versioned table

I am using SQLalchemy with flask to interact with sql server. I have enabled system versioning for the tables. On executing first query to insert or update the table after the app runs , sysstarttime gets updated, but in next subsequent insert or…
2
votes
1 answer

SQLAlchemy utils drop database statement cannot be used inside a user transaction

I have the code below which fails with the message from sqlalchemy_utils.functions import database_exists, create_database, drop_database url = f'mssql+pymssql://user:secret_password@db_host/my_database?charset=utf8' if database_exists(url): …
s5s
  • 11,159
  • 21
  • 74
  • 121
2
votes
2 answers

SQLAlchemy bulk_insert_mappings(): Could not get mapper for table 'test'

I'm stuck trying to use sqlalchemy's bulk_insert_mappings. I got the the point where I can create a session and connect to the db. I have initialized my engine but I can't seem to get the mapper I need from the table. from sqlalchemy import…
rhedak
  • 399
  • 4
  • 13
2
votes
1 answer

Specifying a key for SQLAlchemy's `EncryptedType` at runtime

The SQLAlchemy-Utils documentation for the EncryptedType column type has an example that looks something like this: secret_key = 'secretkey1234' # setup engine = create_engine('sqlite:///:memory:') connection = engine.connect() Base =…
John Wiseman
  • 3,081
  • 1
  • 22
  • 31
1
vote
0 answers

SQLAlchemy: Method to retrieve all rows where a column value is substring of another string

I am using SQLAlchemy to connect to an SQLite database which contains my words I want to retrieve all the rows in which the value of column 'token' is a substring of a string 'myToken' Here's how the class looks: class Word(Base): id =…
1
vote
1 answer

Python SQLAlchemy PostgreSQL Deprecated API features

I am using following code to create the function and trigger to update the created_at and updated_at fields. with upgrade of new module getting the deprecated API warning. How can I replace …
sfgroups
  • 18,151
  • 28
  • 132
  • 204
1
vote
1 answer

String Encrypted Type of JSONType changes are not saved to Database

Backstory I have a questionnaire that asks sensitive questions most of which are true/false. The majority of the time the values are false which poses a challenge when keeping the data private at rest. When encrypting each question into a separate…
Daniel Butler
  • 3,239
  • 2
  • 24
  • 37
1
vote
3 answers

Why BINARY usage in SQLAlchemy with Python3 cause a TypeError: 'string argument without an encoding'

I read a lot of similar questions but none of the clearly answer my issue. I'm using sqlalchemy-utils EncryptedType on a mysql table column. The table creation and the insert is ok, but when I'm trying to do a query a receive: Traceback (most recent…
mda
  • 95
  • 3
  • 8
1
vote
0 answers

SQLAlchemy_utils error: UserWarning: The psycopg2 wheel package will be renamed from release 2.8

Importing sqlalchemy_utils package by doing from sqlalchemy_utils.functions import create_database gives an error message /Users/x/anaconda3/envs/test/lib/python3.7/site-packages/psycopg2/init.py:144: UserWarning: The psycopg2 wheel package will…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
1
vote
1 answer

How to use sqlalchemy_utils.dependent_objects()?

I would like to use the dependent_objects() method to fetch all the relation instances in a database referencing a particular instance in a given relation. I tried the following: uri = "sqlite:///data.sqlite" def getRecord(relName, uuid): …
Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86
1
2 3