SQLAlchemy ORM post v0.4


#1

Hey !

I adapted the sql alchemy backend code pre v0.4 to new components and event hooks so it can be used with latest version.

There is a lot of upcoming work like:

  • A proper settings injection more than environment variables.
  • Commands to create/drop tables.
  • Integration with alembic.

But we don’t have the tools now for defining settings and commands, so I’ll update it as soon as we got them.

Here is the repository with the instructions to use it.


#2

Regarding settings: It’s not that we don’t have settings, it’s that we don’t use global settings anymore. Instead we should configure components at the point of instantating them.

Having the configuration be scoped to the thing it’s relevant to feels so much nicer to me than a bit open global dictionary, tho I’m interested in if there are cases where it’s not sufficient.

I do think we oughta end up with an environment type tho, for validating environment based configuration.


#3

I made my mind to have a huge common settings class splitted in a bunch of mixins for each component due to Django but I agree that having non-shared config scoped seems better.

The point where I’m now is that two different packages that relies on the same config (a database url) so I’m handling it with a environment variable but maybe it should be the same config for those two packages instead of different configs backed by a envvar. Just to bring a bit more info: the case is that package and a health checks package with a check for database connection.


#4

Wouldn’t you want to use scoped_session for thread safety?

Instead of creating the engine in the component why don’t you instead pass in an engine to the component at instantiation time? I didn’t like the original backend component because it could only connect to one Database. This is how I am doing it right now.


#5

I’m happy to improve the lib based on your gist, or even if you want to make a PR that would be great. I just started the project to save my day, and opened it to help anyone but I accept any suggestion or code from anyone :slight_smile:


#6

I updated the library based on your suggestions. Now it uses thread-local sessions and the database url is specified when the component is instantiated.