Comments (6)
Ah, right! db.Session
is a method that returns an instance of db.session_class
, so yeah, what you did is what I intended to suggest.
from alchemical.
How do I track session changes with events?
I am trying to use elastic search for my app. So I was reading the micro-blog tutorial and it use flask-sqlalchemy. So events are implemented this way:
I was trying to do the same with alchemical
but I cannot use sqlalchemy.events
because that would result in RuntimeError: Working outside of application context.
from alchemical.
I'm not sure what is the usage that gives you working outside of app context, but Alchemical does not try to override SQLAlchemy as much as Flask-SQLAlchemy does. Setting events is done directly through SQLAlchemy, as documented here: https://docs.sqlalchemy.org/en/14/core/event.html#event-registration.
from alchemical.
I think that would be the line that causes the error
from alchemical.
You are using db.session
outside of a request. The session does not exist then. I doubt that would even work with Flask-SQLAlchemy, you can't use the session in the global scope. For Alchemical, I think you should be able to pass the session class here, db.Session
(uppercase S).
Note: it does actually work with Flask-SQLAlchemy.
from alchemical.
Thanks. db.Session
(uppercase) would result in an error No such event 'before_commit' for target.
However db.session_class
works. I am yet to investigate and learn. Thanks again
from alchemical.
Related Issues (14)
- What is this? HOT 1
- alchemical.aio.Alchemical with Flask and Flask-Migrate HOT 5
- Multiple Database documentation. HOT 2
- Documentation is not clear HOT 2
- Inheritance mapping: [single-table, joined-table, and concrete-table] does not seem to work. HOT 2
- Check if the table exists HOT 1
- run an arbitrary SQL statement on the database not accurate HOT 1
- Automatically generate migrations HOT 12
- How to set metadata (migrating from Flask-SQLAlchemy)? HOT 2
- docs is not reachable HOT 1
- [Help]Configure Alchemical for testing HOT 2
- Listening for database events in Alchemical HOT 4
- A call to initialize() should fully reset the internal state
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 alchemical.