Giter Site home page Giter Site logo

mardix / active-alchemy Goto Github PK

View Code? Open in Web Editor NEW
120.0 120.0 8.0 497 KB

Active-Alchemy is a framework agnostic wrapper for SQLAlchemy that makes it really easy to use by implementing a simple active record like api, while it still uses the db.session underneath. Inspired by Flask-SQLAlchemy

License: Other

Python 100.00%

active-alchemy's People

Contributors

mardix avatar robroseknows 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

active-alchemy's Issues

Can't validate argument 'bind_key'

After connecting active-sqlalchemy I got strange warnings:

/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py:552: SAWarning: Can't validate argument 'bind_key'; can't locate any SQLAlchemy dialect named 'bind'
self._validate_dialect_kwargs(kwargs)

  • Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
  • Restarting with stat
    /usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py:552: SAWarning: Can't validate argument 'bind_key'; can't locate any SQLAlchemy dialect named 'bind'
    self._validate_dialect_kwargs(kwargs)

Delayed definition of database URI

The ActiveAlchemy constructor expects a URI as first argument, but that URI may not be known at the time that it is created. It would be nice if the constructor accepted None as an alternative value, requiring that we initialise the database URI before interacting with the database. Illustrative example:

db = ActiveAlchemy()

class User(db.Model):
  # ...

def main():
  config = load_config()
  db.bind(config.database_uri)
  db.create_all()
  # ...

Querying in a seperate file

I have set up the models in a model.py page which has classes Article and Website, how can i query those in another page without importing from the model page? Is this possible? I need to write a function that is called in model.py that also queries the db and i cant seem to figure out how to do it without from model import article and running into a circular dependency

Polimorphism not working

$ cat t.py
from flask import Flask, render_template, request
from active_sqlalchemy import SQLAlchemy

app = Flask(name)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
db = SQLAlchemy()

class Alert(db.Model):
mapper_args = {'polymorphic_on': 'type'}
tablename = 'alerts'
id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String(20))

class ComparisonAlert(Alert):
mapper_args = {'polymorphic_identity': "Comparison"}
percent = db.Column(db.Float(), nullable=False, default=10.0)

db.init_app(app)

$ python t.py
Traceback (most recent call last):
File "t.py", line 14, in
class ComparisonAlert(Alert):
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/api.py", line 55, in init
_as_declarative(cls, classname, cls.dict)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/base.py", line 254, in _as_declarative
**table_kw)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 393, in new
"existing Table object." % key)
sqlalchemy.exc.InvalidRequestError: Table 'alerts' is already defined for this MetaData instance. Specify 'extend_existing=True' to redefine options and columns on an existing Table object.

Adding/renaming/deleting columns

So how do I Add a new column to existing db file ?

Also renaming or deleting columns ?

I think sqlacademy cant do it out of the box, but since this is a wrapper maybe its possible ?

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.