Code Monkey home page Code Monkey logo

Comments (13)

agronholm avatar agronholm commented on July 17, 2024

Original comment by kwilcox (Bitbucket: kwilcox, GitHub: kwilcox):


https://bitbucket.org/agronholm/sqlacodegen/pull-requests/2/adding-in-a-contribpy-file-for-external/diff

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

Original comment by Francisco Puga (Bitbucket: fpuga, GitHub: fpuga):


I will be monitoring the ticket to test it and give feedback when the patch will be ready.

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


Answering my own question: just importing geoalchemy2 is enough. Alright, should be a simple enough change. Expect this in 2.0.

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


How do you propose I do that when sqlacodegen relies on SQLAlchemy's reflection?

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

Original comment by Francisco Puga (Bitbucket: fpuga, GitHub: fpuga):


I also think that will be great to be able to create models with the geometry type ( from geoalchemy2 import Geometry )

I'm using sqlacodegen==1.1.6, SQLAlchemy==1.0.11, GeoAlchemy2==0.2.6. When using this tool a get:

$ sqlacodegen postgresql://...
..../local/lib/python2.7/site-packages/SQLAlchemy-1.0.11-py2.7-linux-x86_64.egg/sqlalchemy/dialects/postgresql/base.py:2505: SAWarning: Did not recognize type 'geometry' of column 'the_geom'

The rest of the models are correctly created but for the 'geometry' columns NullType is used.

#!python

the_geom = Column(NullType, index=True)

It's not a big deal, just search for NullType and replace with the correct values. But it will be useful that sqlacodegen can get the custom types from geoalchemy

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


This needs to be fixed upstream so that the geometry column type is recognized. If this conclusion is wrong, reopen the issue.

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


Has anyone successfully reflected a database with such columns?

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


Release 1.1.6 fixes compatibility with SQLAlchemy 1.0. But it still doesn't have the PostgreSQL geometry types.

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


SQLAlchemy 1.0 broke sqlacodegen. I'll have to fix that. Although, can you point me to the proper SQLAlchemy types that these should map to?

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

Original comment by Neil Albrock (Bitbucket: neilalbrock, GitHub: neilalbrock):


I've recently encountered this issue as well. With SQLAlchemy 0.9.9 I get the following:

#!python

/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py:2079: SAWarning: Did not recognize type 'geometry' of column 'geom'
  name, format_type, default, notnull, domains, enums, schema)
/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py:2079: SAWarning: Did not recognize type 'geometry' of column 'extent'
  name, format_type, default, notnull, domains, enums, schema)

With the latest SQLAlchemy 1.0.4 I get this:

#!python

/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py:2421: SAWarning: Did not recognize type 'geometry' of column 'geom
'
  (attype, name))
/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py:2421: SAWarning: Did not recognize type 'geometry' of column 'exte
nt'
  (attype, name))
Traceback (most recent call last):
  File "/home/atomised/.virtualenvs/importizer/bin/sqlacodegen", line 11, in <module>
    sys.exit(main())
  File "/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlacodegen/main.py", line 40, in main
    generator = CodeGenerator(metadata, args.noindexes, args.noconstraints, args.nojoined, args.noinflect)
  File "/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 536, in __init__
    model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
  File "/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 300, in __init__
    relationship_ = ManyToOneRelationship(self.name, target_cls, constraint, inflect_engine)
  File "/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 412, in __init__
    colname = constraint.columns[0]
  File "/home/atomised/.virtualenvs/importizer/local/lib/python2.7/site-packages/sqlalchemy/util/_collections.py", line 191, in __getitem__
    return self._data[key]
KeyError: 0

I hope that helps, it would certainly be good if all Postgres column types could be handled. Let me know if I can offer any assistance.

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


Out of curiosity, does it fail on reflection or in the code generation phase?

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

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


SQLACodegen does not recognize custom types, only built-in ones. It wouldn't know where to import those from anyway.

from sqlacodegen.

agronholm avatar agronholm commented on July 17, 2024

Closing this as it is superseded by #29.

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.