Comments (6)
Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):
Numeric columns produce Decimal instances while Real produces floats. These two are not the same and replacing one with the other would be an error. What you can do, however, is use a serialization hook with json that turns Decimals into strings automatically.
I have no idea what you're proposing regarding arrays.
from sqlacodegen.
Original comment by hamx0r (Bitbucket: hamx0r, GitHub: hamx0r):
I wasn't aware it already used generic datatypes. When I used json
to convert query results from a Postgres DB containing Numeric
columns, it threw an error. I manually updated models.py
(which was generated from sqlacodegen) to use Real
for the columns instead of Numeric
, then json
was able to convert them just fine. This implies the postgres column types were being used in the models instead of generic types.
In the case of how to handle non-arrays, I think the solution would be to return it as a single string (which I believe Postgres will do in the form [item1, item2, etc]
. The user can then parse into a list as needed.
from sqlacodegen.
Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):
But sqlacodegen already uses generic datatypes wherever possible. What would you expect it to use in case it detects a PostgreSQL array? You didn't say.
from sqlacodegen.
Original comment by hamx0r (Bitbucket: hamx0r, GitHub: hamx0r):
To clarify (in cases this gets reopened), what I'm asking for is a way of to use sqlacodegen with the ability to say whether to prefer non-dialectal datatypes. For example, add a --no-dialect
flag.
What this flag would do is cause sqlacodegen to generate DB models, but use datatypes which are "generic" or not dialect-specific. For example, Postgres supports column types which are 'arrays'. Say, an array of text items ([text]
). MySQL does not support columns of type array. Thus, if one were switch between DB clones of different SQL dialects (ie switch between Postgres and MySQL), they'd have to edit their models.py
to make them compatible.
The feature I'm re questing would create a dialect-agnostic models.py
which would allow this switch between Postgres and MySQL without any code changes.
Furthermore, Postgres has a Numeric column type used to represent floating point numbers. This datatype is not usable with the json
Python module, so it throws an error when trying to create JSON strings from SQLAlchemy query results. However, the more generic Real
type is supported by MySQL and Postgres, and Reals
are properly converted to longs
by the json
module. Using my proposed --no-dialect
flag would create a models.py
where Numeric
columns would be turned into Real
columns.
My rationale with this request is to make models
which can be used with multiple SQL servers of different dialects, and to be more compatible with the json
module as it is frequently used when making REST APIs backed by SQLAlchemy.
from sqlacodegen.
Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):
Over 2 months and no feedback -- closing.
from sqlacodegen.
Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):
I have no idea what you're asking me to do.
from sqlacodegen.
Related Issues (20)
- Enhancement: Add Support for pgvector extension HOT 2
- SQLModel codegen produces syntax errors HOT 6
- Syntax Error in 3.0.0rc3 HOT 5
- No poetry package which supports SQLAlchemy 2.0 HOT 5
- AssertionError: TypeDecorator implementations require a class-level variable 'impl' HOT 14
- sqlalchemy.exc.OperationalError HOT 6
- Database URL is split on & HOT 1
- No module named 'pkg_resources' HOT 2
- ImportError: cannot import name 'ArgSpec' from 'inspect' HOT 1
- Can we push more versions to PyPi HOT 5
- Using types instead of strings in return values of methods in generators
- Issue when generating Postgres DOMAIN type HOT 2
- Could not assemble any primary key when using the SQLModel generator
- UUID for postgreSQL HOT 1
- Attribute error module 'sqlalchemy' has no attribute '__all__'. Did you mean: '__file__'? for mysql HOT 2
- MySQL DOUBLE(11,2) is converted to Double(11, True)
- Child table ORM classes inheriting from base tables are not generated HOT 5
- Installed on my windows10 python 3.12.4, get incompatible error HOT 3
- Missing many-to-many relationship HOT 1
- Error when reading vector column of pgvector HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlacodegen.