Open marshallswain opened 1 year ago
Latest commit: d663c5cc6aacb12489200946fd0fc77b8358a0d6
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
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 We'd likely want to add something here to improve the inference functionality for JSON columns, so that the user doesn't have Typescript errors
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
TEXT
column 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
json
boolean to theModelColumn
interface.columns
config to theGenerateQueryOptions
INSERT
andINSERT_OR_REPLACE
to check for a column config and give special treatment ifcolumn.json
is truthy.Model.InsertOne
method to passcolumns
in the options.I've run the code in wrangler dev to make sure it works in "production".