-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 native database composite types (CREATE TYPE
)
#4263
Comments
I agree, would love to see it! |
Can one of you share a SQL schema of such a type and possibly how you would want to see this represented in your Prisma Schema? |
@janpio I've crafted these schemas based on the content of this post where the author hacked composite types into TypeORM. It implements a This is mostly an initial suggestion from someone who has not been using Prisma yet, but been evaluating a migration from TypeORM and would like to see this feature get into Prisma, but I believe it's a good starting point. In this reddit thread there's some further discussion into whether composite types are an appropriate solution to this issue and how, unfortunately, lack of support on client side is usually a hindrance. SQL Schema CREATE TYPE currency AS ENUM ('USD');
CREATE TYPE price AS (
currency currency,
amount INTEGER
);
CREATE TABLE plan (
id SERIAL PRIMARY KEY,
price price NOT NULL
); Possible Prisma Schema enum Currency {
USD
}
type Price {
currency Currency
amount Int
}
model Plan {
id Int @id @default(autoincrement())
price Price
} |
I assume this would mean working on the prisma-engines dataformat parser, and implementing appropriate translation to supported targets, but I'm too unfamiliar with the project structure to try implementing something like this myself. Is there any documentation on the whole pipeline, where all the corresponding source is, and how someone could go about extending PSL? |
i hope this gets added because having already typed json objects would be so much nicer than creating types/interfaces that implement the json type, to then cast the custom type everytime you want to use data from that json |
I am in need of the same thing: either through composite types or typed JSON. |
Any ideas here? this is obviously needed, and it is definitely supported in PostgreSQL |
Would love support for composite types. postgres does provide type structure of directly-user-defined composite types via |
CREATE TYPE
)
Just to make sure: This issue is about https://www.postgresql.org/docs/current/sql-createtype.html for PostgreSQL, correct? Do other databases also support similar constructs? If you are looking for type JSON columns, please 👍 this issue: #3219 |
Please just implement it. |
yeah, the issue is about at least being able to model this: |
I'd love to see the ability to create composite types for |
This would be an awesome addition |
CREATE TYPE "TransactionMessage" AS (
header "TransactionMessageHeader",
account_keys BYTEA[],
recent_blockhash BYTEA,
instructions "CompiledInstruction"[]
); It failed to generate anything from 'db pull', model transaction {
slot BigInt
signature Bytes
is_vote Boolean
message_type Int? @db.SmallInt
legacy_message Unsupported("TransactionMessage")?
v0_loaded_message Unsupported("LoadedMessageV0")?
signatures Bytes[]
message_hash Bytes?
meta Unsupported("TransactionStatusMeta")?
write_version BigInt?
updated_on DateTime @db.Timestamp(6)
@@id([slot, signature], map: "transaction_pk")
} Got stuck here and the best thing is to query the whole thing raw, const result = await prisma.$queryRaw`select
to_jsonb(signature) as signature,
to_jsonb(signatures) as signatures,
to_jsonb(legacy_message) as legacy_message,
to_jsonb(v0_loaded_message) as v0_loaded_message,
to_jsonb(meta) as meta
from
public."transaction"
where
slot = 1204`;
console.log(JSON.stringify({ result }, null, 2)); |
Really could use this feature |
Any progress? This is very useful for migrating existing schemas to prsima/using the full potential of postgresql (does cockroach support composite types like postgresql since it's compatible with postgresql?) |
Without this feature, I'm running into a problem where I have to create a new table for any complex object that a table might have more than one of, even if we never need to query that object directly. That results in deeply nested database schemas and inefficient reads and writes. Has anyone found a good workaround for this? |
Any updates on composite types on postgres? Would like to see that feature implemented. |
+1 |
Storngly need this |
This will be useful. |
This comment was marked as outdated.
This comment was marked as outdated.
I'm assuming postgres should have optimizations for this kind of structure, since it is largely parrallel, but I don't know much about postgres yet. |
Any progress? Or a temporary solution to implement this using the new $extends added in Prisma 5? |
I am running into this same issue, and I now have to resort to uncoupling every table that references my "data structure" tables because this approach is scaling horribly in my project. I'd really love to see some progress with this. |
- Switch planetscale driver to array mode too - For neon-http, pass `arrayMode` and `fullResult` options on all invocations, making us agnostic to the settings used in constructor.
+1 for me also, seems odd this is available for mongo and not postgres? But doesn't look like this will ever be a thing, as there seems to be nothing from the team on this one? :( |
That the issue is not closed is an indication that we consider this a relevant and valid feature request. |
I would love to see this implemented. Currently working on a rather big structure and having custom data types would help greatly, making the code, schemas and tables so much cleaner and possibly more optimized. Not having this option is lacking one of the best Postgres' features. |
Hope it's in progress 🙏🏾🙏🏾 |
would love to see this for mysql surprised it doesnt support composite types. I'm not really sure how to do nested objects that are type safe otherwise. |
Problem
I found out I needed to implement a composite type (an integer type and a text type all as a single type called block) in my postgresql database for a project I am working on. I had implemented Prisma throughout most of my backend only to add this type in the db, introspect, and then see that field commented our in my schema.prisma file saying that the type is not currently supported. I looked through the docs and sure enough, no support for composite types. Now it looks I have to completely rip Prisma out of my project and find something else(although not sure what, cuz there isn't jack s*%$ for decent ORM's with node, if anyone knows something else good feel free to let me know).
There have have been other issues that I have dealt with (like not being able to delete entities with relations using the .delete() function, which I mean come on, how is that still an issue... that should be a basic feature) but at least they had work arounds, like just using executeRaw with some raw SQL to perform the delete. But this issue with no support for composite types does not seem to have any work around (outside of changing my db structure).
Suggested solution
Add support for composite types. (And fix the delete issue.)
Alternatives
Some sort of work around for those who already have composite types in use in their db and need to be able to use them with Prisma.
The text was updated successfully, but these errors were encountered: