Code Monkey home page Code Monkey logo

sqla-wrapper's Introduction

๐Ÿช Hi! I'm Juan Pablo

I develop open-source software, primarily Python tools and libraries, to satisfy my own needs, curiosity, and interests, but maybe you will find them useful too ๐Ÿ˜‰

I am open to work, reach me out by email at [email protected] ๐Ÿ“ซ and on LinkedIn or Twitter/X

sqla-wrapper's People

Contributors

calebdinsmore avatar curiousdima avatar dependabot[bot] avatar glogiotatidis avatar imran2140 avatar jcn avatar jpsca avatar krnr avatar ondoheer avatar ramuta avatar sloria avatar vsurjaninov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqla-wrapper's Issues

Add association_proxy to sqlalchemy_wrapper.SQLAlchemy

When trying to migrate my project to sqlalchemy-wrapper, I have spotted incomplete imports of useful functions for declarative model:

from sqlalchemy_wrapper import SQLAlchemy

db = SQLAlchemy(...)
db.relationship # works
db.association_proxy # not found
from sqlalchemy.ext.associationproxy import association_proxy # works - provided by vanilla SQLAlchemy

Could you please add the association_proxy to sqlalchemy_wrapper.SQLAlchemy?

default extend_existing to True

In model.py after cls.__tablename__ = _get_table_name(cls.__name__),
would you consider adding
cls.__table_args__ = {'extend_existing':True}?

It allows to change the model interactively, e.g. in IPython.

Does it support Asynchronous I/O?

As we know it's base on SQLAlchemy 1.4 from 5.0.0, Asynchronous I/O is theoretically supported.

Would you provide some example using in sqla-wrapper?

Wrong syntax in quickstart doc

Quickstart show examples like this

users = User.query.all()

But that syntax is not supported yet, the correct one should be:

users = db.query(User).all()

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 63: ordinal not in range(128)

Orignal Query -

data = db.session.query(PublishEvent, ImageLicense).join(PublishEvent.images).join(ImageLicense).filter(ImageLicense.licensed_at != None')

Traceback -

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
    245             self.start_displayhook()
    246             self.write_output_prompt()
--> 247             format_dict, md_dict = self.compute_format_data(result)
    248             self.write_format_data(format_dict, md_dict)
    249             self.update_user_ns(result)

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
    155
    156         """
--> 157         return self.shell.display_formatter.format(result)
    158
    159     def write_format_data(self, format_dict, md_dict=None):

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
    150             md = None
    151             try:
--> 152                 data = formatter(obj)
    153             except:
    154                 # FIXME: log the exception

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    479                 type_pprinters=self.type_printers,
    480                 deferred_pprinters=self.deferred_printers)
--> 481             printer.pretty(obj)
    482             printer.flush()
    483             return stream.getvalue()

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    345                 if cls in self.type_pprinters:
    346                     # printer registered in self.type_pprinters
--> 347                     return self.type_pprinters[cls](obj, self, cycle)
    348                 else:
    349                     # deferred printer

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/lib/pretty.pyc in inner(obj, p, cycle)
    529                 p.text(',')
    530                 p.breakable()
--> 531             p.pretty(x)
    532         if len(obj) == 1 and type(obj) is tuple:
    533             # Special case for 1-item tuples.

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    345                 if cls in self.type_pprinters:
    346                     # printer registered in self.type_pprinters
--> 347                     return self.type_pprinters[cls](obj, self, cycle)
    348                 else:
    349                     # deferred printer

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/lib/pretty.pyc in inner(obj, p, cycle)
    529                 p.text(',')
    530                 p.breakable()
--> 531             p.pretty(x)
    532         if len(obj) == 1 and type(obj) is tuple:
    533             # Special case for 1-item tuples.

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    360                             if callable(meth):
    361                                 return meth(obj, self, cycle)
--> 362             return _default_pprint(obj, self, cycle)
    363         finally:
    364             self.end_group()

/Users/newscred/.virtualenvs/nc-reporting/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    480     if getattr(klass, '__repr__', None) not in _baseclass_reprs:
    481         # A user-provided repr.
--> 482         p.text(repr(obj))
    483         return
    484     p.begin_group(1, '<')

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 63: ordinal not in range(128)

db.init_app() doesnt apply app's configuration

I am trying to initialize the database through a factory function as i have circular import problems.

# __init__.py
db = SQLAlchemy()

def create_app(config):
    app = Flask(__name__, instance_relative_config=True, static_url_path='')
    # Didnt test if Toolbar works with this way yet but anyway..
    toolbar = DebugToolbarExtension(app)
    app.config.from_object(config)
    if 'APP_CONFIG_FILE' in os.environ:
        app.config.from_envvar('APP_CONFIG_FILE')

    db.init_app(app)
# config.py
from os.path import dirname, abspath

class DefaultConfiguration:
    DATABASE = 'my_database.db'
    SQLALCHEMY_DATABASE_URI = ('sqlite:///' + dirname(abspath(__file__)) +
                               '/' + DATABASE)
    TESTING = False
    DEBUG = False
    DEBUG_TB_INTERCEPT_REDIRECTS = False
    RECORD_QUERIES = False
    SECRET_KEY = 'Basic_key_thats_supposed_to_be_secret'
    BCRYPT_LEVEL = 12
    USERNAME = 'admin'
    PASSWORD = 123

I tried to pdb and everytime db shows sqlite:// (memory) even though app.config shows correct information about DATABASE_URI and DATABASE. I tried to initialize before and after the configuration fo the app(app.config.from_object).
I am not expert what so ever so i might miss something!

Incompatible with just-released SQLAlchemy 2.0

Partial of the traceback:

...
db = SQLAlchemy(
^^^^^^^^^^^
File "/home/ubuntu/workspace/nb/.venv/lib/python3.11/site-packages/sqla_wrapper/sqlalchemy_wrapper.py", line 94, in init
self._include_sqlalchemy()
File "/home/ubuntu/workspace/nb/.venv/lib/python3.11/site-packages/sqla_wrapper/sqlalchemy_wrapper.py", line 126, in _include_sqlalchemy
for key in module.all:
^^^^^^^^^^^^^^
AttributeError: module 'sqlalchemy' has no attribute 'all'. Did you mean: 'file'?

Flask debug toolbar doesnt show queries(shows unavailable)

As i am trying to make the "transition" from Flask-SQLAlchemy to your fork i found this problem where the debug toolbar doesnt show information about the queries, it just tells me that i have to install Flask-SQLAlachemy.

I saw a commit about supporting the toolbar in your fork but im not expert to debug what is wrong cause maybe im missing something.

# __init__.py
from flask import Flask
from sqlalchemy_wrapper import SQLAlchemy
from flask.ext.bcrypt import Bcrypt

app = Flask(__name__, instance_relative_config=True, static_url_path='')
bcrypt = Bcrypt(app)

app.config.from_pyfile('development.py')

db = SQLAlchemy(app.config['SQLALCHEMY_DATABASE_URI'], app=app)
# run.py
from flask_debugtoolbar import DebugToolbarExtension
toolbar = DebugToolbarExtension()
toolbar.init_app(app)

Did `PatchedScopedSession` function's argument naming correct?

sqlalchemy_wrapper.py line 82-83

self.Session = sqlalchemy.orm.sessionmaker(**session_options)
self.s = PatchedScopedSession(self.Session)
class PatchedScopedSession(scoped_session):
    pass

The argument pass to PatchedScopedSession is naming scoped_session, but maybe it's not scoped session, it's default session.

Inheritance does not work properly

Because db.Model explicitly defines __tablename__, STI doesn't work since the declarative_base expects __tablename__ to be undefined to work properly.

http://docs.sqlalchemy.org/en/rel_1_0/orm/inheritance.html?highlight=inheritance#single-table-inheritance

flask-sqlalchemy actually had the same problem at one point and they fixed this by checking to see whether the table name should actually be set in different instances: https://github.com/mitsuhiko/flask-sqlalchemy/blob/master/flask_sqlalchemy/__init__.py#L553-L591

Two Pypi (pip) packages

Hi!

There are two Pypi packages for this project:

The latter is probably the correct one (or the latest one), but having two pip packages can confuse users. Please either delete the SQLAlchemy-Wrapper package or add a notice in the README.md file to install sqla-wrapper.

Usually readme files start with installation instructions: pip install sqla-wrapper. This makes it clear which package to install.

Existing DB

How would one use sql-wrapper with existing db?

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.