penguinolog / sqlalchemy_jsonfield

SQLALchemy JSONField implementation for storing dicts at SQL independently from JSON type support
Apache License 2.0
22 stars 2 forks source link

Runtime changes for local development only #4

Open alper opened 5 years ago

alper commented 5 years ago

I'd like to use this without changing the db.Model, is that possible?

The use case:

penguinolog commented 5 years ago

This lib can use native JSON for MySQL (de-facto it's sqlalchemy json) and text for sqlite without any migrations. If you want - you can fork this project with you local specific code. On Sun, 13 Jan 2019, 14:11 Alper Cugun <notifications@github.com wrote:

I'd like to use this without changing the db.Model, is that possible?

The use case:

  • We use MySQL in production which has JSON
  • Locally we want to test in sqlite which does not really have it (the extension is a bit annoying to use)
  • Can I drop in this project without any changes to the Model purely for local development. So when the database is sqlite and there is no JSON support, override it to store strings?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/penguinolog/sqlalchemy_jsonfield/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/APSmM1sXbaoOm43R4htK5yiyIrLhHnJPks5vCzCWgaJpZM4Z9KS6 .

alper commented 5 years ago

I mean the Model has:

attributes = db.Column(db.JSON())

Can I make this work without changing that part?

Update: I got it to work by changing it into: attributes = sqlalchemy.Column(sqlalchemy_jsonfield.JSONField(enforce_string=True))

But I'd prefer not to modify my original source code. Any way to do that?

penguinolog commented 5 years ago

You need to split logic for db, which support JSON natively and db with encode/decode. That's why this lib was made - I also had such pain

On Sun, 13 Jan 2019, 20:55 Alper Cugun <notifications@github.com wrote:

I mean the Model has:

attributes = db.Column(db.JSON())

Can I make this work without changing that part?

Update: I got it to work by changing it into: attributes = sqlalchemy.Column(sqlalchemy_jsonfield.JSONField(enforce_string=True))

But I'd prefer not to modify my original source code. Any way to do that?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/penguinolog/sqlalchemy_jsonfield/issues/4#issuecomment-453860362, or mute the thread https://github.com/notifications/unsubscribe-auth/APSmM2AmkWVALBXaae9TB0ikQIe3a0Wsks5vC48tgaJpZM4Z9KS6 .