Interactions-as-a-Service / d1-orm

A simple, strictly typed ORM, to assist you in using Cloudflare's D1 product
https://docs.interactions.rest/d1-orm/
Apache License 2.0
162 stars 11 forks source link

JSON support proposal, currently only for INSERT #67

Open marshallswain opened 1 year ago

marshallswain commented 1 year ago

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 a columns? property in the options.

Changes to note

I've run the code in wrangler dev to make sure it works in "production".

changeset-bot[bot] commented 1 year ago

⚠️ No Changeset found

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.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

Skye-31 commented 1 year ago

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?

Skye-31 commented 1 year ago

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