Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
prisma-kysely
Advanced tools
🚧 Library and README in progress...
Do you like Prisma's migration flow, schema language and DX but not the limitations of the Prisma Client? Do you want to harness the raw power of SQL without losing the safety of the TypeScript type system?
Enter prisma-kysely
!
Install prisma-kysely
using your package manager of choice:
yarn add prisma-kysely
Replace (or augment) the default client generator in your schema.prisma
file with the following:
generator kysely {
provider = "prisma-kysely"
// Optionally provide a destination directory for the generated file
// and a filename of your choice
output = "../src/db"
fileName = "types.ts"
// Optionally generate runtime enums to a separate file
enumFileName = "enums.ts"
}
Run prisma migrate dev
or prisma generate
and use your freshly generated
types when instantiating Kysely!
Prisma's migration and schema definition workflow is undeniably great, and the typesafety of the Prisma client is top notch, but there comes a time in every Prisma user's life where the client becomes just a bit too limiting. Sometimes we just need to write our own multi table joins and squeeze that extra drop of performance out of our apps. The Prisma client offers two options: using their simplified query API or going all-in with raw SQL strings, sacrificing type safety.
This is where Kysely shines. Kysely provides a toolbox to write expressive,
type-safe SQL queries with full autocompletion. The problem with Kysely though
is that it's not super opinionated when it comes to schema definition and
migration. What many users resort to is using something like Prisma to define
the structure of their databases, and kysely-codegen
to introspect their
databases post-migration.
This package, prisma-kysely
, is meant as a more integrated and convenient way
to keep Kysely types in sync with Prisma schemas. After making the prerequisite
changes to your schema file, it's just as convenient and foolproof as using
Prisma's own client.
I've been using this combo for a few months now in tandem with Cloudflare's D1 for my private projects and Postgres at work. It's been a game-changer, and I hope it's just as useful for you! 😎
Key | Description |
---|---|
output | The directory where generated code will be saved |
fileName | The filename for the generated file |
enumFileName | The filename for the generated enums. Omitting this will generate enums and files in the same file. |
camelCase | Enable support for Kysely's camelCase plugin |
[typename]TypeOverride | Allows you to override the resulting TypeScript type for any Prisma type. Useful when targeting a different environment than Node (e.g. WinterCG compatible runtimes that use UInt8Arrays instead of Buffers for binary types etc.) Check out the config validator for a complete list of options. |
By default (no pun intended) the Prisma Query Engine uses JS based
implementations for certain default values, namely: uuid()
and cuid()
. This
means that they don't end up getting defined as default values on the database
level, and end up being pretty useless for us.
Prisma does provide a nice solution to this though, in the form of
dbgenerated()
. This allows us to use any valid default value expression that
our database supports:
model PostgresUser {
id String @id @default(dbgenerated("gen_random_uuid()"))
}
model SQLiteUser {
id String @id @default(dbgenerated("(uuid())"))
}
Check out the Prisma Docs for more info.
OMG you actually want to contribute? I'm so thankful! 🙇♂️
Here's everything you need to do (let me know if something's missing...)
yarn install
and yarn dev
to start tsc
in watch mode.prisma/schema.prisma
, running yarn prisma generate
and checking the output in prisma/types.ts
. The provider must be set
as follows to reference the dev build:
generator kysely {
provider = "node ./dist/bin.js"
}
I'm not 100% sure the type maps are correct for every dialect, so any and all contributions on that front would be greatly appreciated. The same goes for any bug you come across or improvement you can think of.
prisma-dbml-generator
.
Many-too-many thanks to them!+ Boyce-Codd gang unite! 💽
1.3.0
FAQs
Generate Kysely database types from a Prisma schema
The npm package prisma-kysely receives a total of 17,144 weekly downloads. As such, prisma-kysely popularity was classified as popular.
We found that prisma-kysely demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.