New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Json
field type in SQLite
#3786
Comments
Would love to see this implemented in Prisma! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
Do you have any update regarding this? Please tell us so those of us who need JSON field type support can decide whether to skip Prisma. |
I am interested in this to make Prisma even more viable for interacting with SQLite from an electron app or CLI app. |
This is the first result that comes up for |
I'd like to also vote for this feature. |
This comment was marked as off-topic.
This comment was marked as off-topic.
At this point the lack of response is more concerning than the lack of this feature. |
We never respond to feature requests unless we concretely work on issues, need more information or similar. |
It has been mentioned that people use SQLite for local development, but I'm evaluating Prisma for a project where SQLite is a (soft-) requirement for production use. Of course this can be worked around by using text fields, but that would limit the both leverage of what SQLite provides out of the box and the utility of using Prisma. I'm hopeful for a more feature complete integration with SQLite. |
With Until this lands, is there any workaround that can be used for simple use cases (just querying and writing w/o and fancy filtering functions)? Idea is, that we could use this datatype in schema definitions and implement something like a custom adapter/plugin for local sqlite development to handle the de-/serialization. |
We want to support both Sqlite and PostgreSQL in Webstudio and while migrating from MongoDB discovered the missing support for JSON type. With the recent motion in favor of SQLite serverside by multiple startups and announcement of D1 from cloudflare, this should be a priority for Prisma. |
Can we sponsor this feature? I'm really interested in offering a |
Relevant information that changes the situation for this issue:
🚀! What could help here right now: |
This comment was marked as off-topic.
This comment was marked as off-topic.
+1 I'm trying Prisma on a CLI app and I reached this "inconvenience". |
Any updates on this? Why is JSON not implemented in SQLite while it's in PostgreSQL? thx! |
Because JSON was not enabled by default in the past on SQLite, see the message above. |
What do you mean by "add the Json column by hand"? @janpio |
Prisma can not handle and create JSON columns for SQLite. So to be able to test the queries we use, you would need to add a Json column manually to the SQLite database and then run the queries against that SQLite database with that column present to be able to tell us if they all work, or horribly crash. |
hi janpio, appreciate the work! |
+1 |
+1 to this, now JSON is natively supported in SQLite. And this must be easy to implement since the syntax and everything is already in place for postgres. |
Can we at least enable it under a preview feature flag? |
If someone does a PR to add it to our codebases under a preview feature flag, sure. To be accepted it will require tests as well though. We currently are working on other things, so this is a not a priority and no one can spend time on it. As soon as this changes, we might tackle this. |
@janpio Really don't get why my "+1" comment above was "marked as abuse" (I'm assuming this was done by you or someone else on the Prisma team since I can't seem to report other comments as abuse. If not, I'm sorry.) I sense a mild annoyance with this feature request in general in your comments and to a certain degree I get that, but to quote from the prisma guidelines for feature requests:
I didn't add a comment since I felt it wouldn't add much, since the feature was clear and already discussed extensively. I don't know if these reports are something that GitHub tracks about me, but I wouldn't want for this to lead to any issues with my account in the future so I would really appeciate it if you could reverse the report if that is possible. |
I updated the README to avoid such a misunderstanding, and clarified that issues should get a 👍 reaction.
And that you "sense mild annoyance with this feature request" is you reading too much into what I wrote (or did not write). I am pretty eager to get this feature implemented - just don't have the capacity to prioritize it right now. (Sorry for everyone being subscribed to the isseu that now also got a notification about this message.) |
the basics of javscript JSON.stringfy
|
Maybe we can use sqld to mimic postgresql for now, and test prisma against it? |
Json
field type in SQLite
I wanted to add my eagerness for this to be implemented as well, as well as get notified if there is movement on this ticket! Thanks Prisma team! P.S. for anyone interested the best hack I have for now is doing this: and then I have prisma middleware that is aware of the default values and knows how to the treat them from there... |
I'm not sure why it's taken this long for someone to pipe up here, but the answer is simply "no" here. Here are some initial findings with a small subset of the functions, but I didn't bother continuing to research as it just seems like the Prisma implementation of how it handles the JSON queries is just not compatible with SQLite. My Prisma model is: model User {
id String @id @default(uuid())
data Json
} An INSERT INTO "public"."User" ("id","data") VALUES ($1,$2) RETURNING "public"."User"."id", "public"."User"."data"
["918bab14-5f26-4ef5-bed9-0661156a09a7",{"foo":"bar"}] but SQLite expects the Perhaps that's a logging or library manipulation mismatch issue however, so looking at one of the more complicated queries: await prisma.user.findFirst({
where: {
data: {
path: ["foo"],
equals: "bar"
}
}
}); looks like:
SQLite errors: A comparable call in SQLite would look like: SELECT "User"."id", "User"."data" FROM "User" WHERE "User"."data"->'$.foo' = '"bar"' LIMIT 1 OFFSET 0 or using SELECT "User"."id", "User"."data" FROM "User" WHERE "User"."data"->>'$.foo' = 'bar' LIMIT 1 OFFSET 0 or removing the |
SQLite’s 3.45.0 release introduces changes to JSON data handling, using JSONB as the new internal format for all JSON functions, which now generate binary JSONB under the hood. This might be a good time to revisit the implementation of JSON field type support in Prisma for >= SQLite 3.45.0. |
Is there any temporary solution for this? |
@ryantando I am specifying the type of the field as client = new PrismaClient({
datasourceUrl,
}).$extends({
result: {
playerCharacter: {
metadata: {
needs: { metadata: true },
compute(obj) {
return JSON.parse(obj.metadata as string);
},
},
},
},
query: {
playerCharacter: {
create({ args, query }) {
args.data.metadata = JSON.stringify(args.data.metadata);
return query(args);
},
update({ args, query }) {
if (args.data.metadata !== undefined) {
args.data.metadata = JSON.stringify(args.data.metadata);
}
return query(args);
},
updateMany({ args, query }) {
if (args.data.metadata !== undefined) {
args.data.metadata = JSON.stringify(args.data.metadata);
}
return query(args);
},
upsert({ args, query }) {
args.create.metadata = JSON.stringify(args.create.metadata);
if (args.update.metadata !== undefined) {
args.update.metadata = JSON.stringify(args.update.metadata);
}
return query(args);
},
},
},
}); |
Problem
SQLite has had support for JSON field type for a while.
Sequelize
supports this field type on par with Postgres and MySQL.Lack of support for this field type by Prisma is preventing us from porting over our project.
SQLite is a great bootstrapping technology that allows developers to quickly prototype applications without introducing new dependencies such as docker or worry about running yet another service in the development flow. JSON field type gives us the option to have a
nosql
database colocated in asql
database.Suggested solution
Please implement support for this feature. See JSON
Extensiondocumentation and refer toSequelize
's implementation if required.Alternatives
Defer migration to Prisma and stick with
Sequelize
. Maintain status quo.Additional context
cc: @ryands17
ref: #3575
The text was updated successfully, but these errors were encountered: