sqlalchemy_jsonfield icon indicating copy to clipboard operation
sqlalchemy_jsonfield copied to clipboard

Runtime changes for local development only

Open alper opened this issue 7 years ago • 3 comments

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?

alper avatar Jan 13 '19 13:01 alper

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 <[email protected] 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 .

penguinolog avatar Jan 13 '19 16:01 penguinolog

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?

alper avatar Jan 13 '19 19:01 alper

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 <[email protected] 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 .

penguinolog avatar Jan 13 '19 20:01 penguinolog