You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 21, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 21, 2020. It is now read-only.
Prisma 2 defines core primitive types (in this document used interchangeably with Prisma scalar), all connectors implement this types natively or as best effort implementation. There are a couple of questions I have on how this would play with custom types.
Use Cases
A custom type that cannot be backed by a Prisma scalar
To support custom types, we can create a type alias in the Prisma schema file and back it by a Prisma core type. Let us use Postgres's BIGINT as an example.
We could define this type as following but assume that the Int core type of connector's programming language (Say we are writing Postgres connector in JS) is not big enough for the underlying data source's (in this case Postgres's) BigInt
// Not possible in a JS connector as JS integer cannot hold Postgres's BIGINT (Yet, soon™: https://v8.dev/blog/bigint)
type LargeNumber = Int @pg.BIGINT
So, we defined a type and use it like this backing a BIGINT with a String:
type LargeNumber = String @pg.BIGINT
model Planet {
id Int @id
population LargeNumber
}
These lines have enough information to generate a Photon client that has the following API (say, for create):
This usage might require coercion in Photon or the query engine or the data source itself. What/where it exactly happens needs further spec.
Related notes:
Same question can be asked for types that are not representable with an existing Prisma core type like BLOB. Will we add more Prisma core primitive types?
How does type Json = String @pg.json behave if the user input is not valid JSON → Does photon or some other part of stack reject it? What part of stack identifies an input variable as JSON and tries to coerce/parse it?
I'm not sure it make much sense to even allow type aliases (at least until a use case comes up). I know we've talked about this list being virtually converted to prisma's schema language on the fly for VSCode's "Go To Definition", but I'm not sure if we should allow the user to arbitrarily define types like type BigNumber = String @pg.bigint.
Hi guys, do you have some information about progress on this? I just hit a point where I want to use DATE type in PostgreSQL to be able to use native sorting functionality but it is not possible. Fetching all data and then sorting them on the server seems to be a very inefficient solution.
Activity
matthewmueller commentedon Sep 3, 2019
Database capabilities are a dependency to the generators. Inside the database capabilities we'll have a list like this:
I'm not sure it make much sense to even allow type aliases (at least until a use case comes up). I know we've talked about this list being virtually converted to prisma's schema language on the fly for VSCode's "Go To Definition", but I'm not sure if we should allow the user to arbitrarily define types like
type BigNumber = String @pg.bigint.malekjaroslav commentedon Nov 19, 2019
Hi guys, do you have some information about progress on this? I just hit a point where I want to use
DATEtype in PostgreSQL to be able to use native sorting functionality but it is not possible. Fetching all data and then sorting them on the server seems to be a very inefficient solution.janpio commentedon Aug 22, 2020
Replaced by prisma/orm#446