JSON support proposal, currently only for INSERT#67
JSON support proposal, currently only for INSERT#67marshallswain wants to merge 1 commit intoInteractions-as-a-Service:mainfrom
Conversation
|
|
Hey 🙋♀️ Thanks for this! I definitely like the idea of introducing JSON support to the library. I'm curious to hear your ideas as to how this would be done for Updating and Selecting - what if a user wants to query based on something within one of the columns? |
|
https://github.com/marshallswain/d1-orm/blob/d663c5cc6aacb12489200946fd0fc77b8358a0d6/src/model.ts#L347-L358 |
Purpose
This is the beginning of a proposal/spec for supporting JSON. The goal was to reveal a pattern that can be applied to other Model and QueryBuilder methods. I'd like to get opinions before I commit to the remaining query methods.
Context
JSON support requires some sort of schema because it uses a
TEXTcolumn type, but requires additional context/knowledge that the column should be treated as JSON. With this in mind, the QueryBuilder has been updated to accept acolumns?property in the options.Changes to note
jsonboolean to theModelColumninterface.columnsconfig to theGenerateQueryOptionsINSERTandINSERT_OR_REPLACEto check for a column config and give special treatment ifcolumn.jsonis truthy.Model.InsertOnemethod to passcolumnsin the options.I've run the code in wrangler dev to make sure it works in "production".