Giter VIP home page Giter VIP logo

Comments (6)

agronholm avatar agronholm commented on July 17, 2024

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.

agronholm avatar agronholm commented on July 17, 2024

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.

agronholm avatar agronholm commented on July 17, 2024

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.

agronholm avatar agronholm commented on July 17, 2024

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.

agronholm avatar agronholm commented on July 17, 2024

Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):


Over 2 months and no feedback -- closing.

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.