Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@vercel/postgres-kysely
Advanced tools
A client that works with Vercel Postgres.
Note: If you want to write your own queries instead of using an ORM, see @vercel/postgres.
pnpm install @vercel/postgres-kysely
Kysely is a peer dependency of this project, so you need to install it as a dependency for your project:
pnpm i kysely
Specify a schema:
import { Generated, ColumnType } from 'kysely';
interface PersonTable {
// Columns that are generated by the database should be marked
// using the `Generated` type. This way they are automatically
// made optional in inserts and updates.
id: Generated<number>;
first_name: string;
gender: 'male' | 'female' | 'other';
// If the column is nullable in the database, make its type nullable.
// Don't use optional properties. Optionality is always determined
// automatically by Kysely.
last_name: string | null;
// You can specify a different type for each operation (select, insert and
// update) using the `ColumnType<SelectType, InsertType, UpdateType>`
// wrapper. Here we define a column `modified_at` that is selected as
// a `Date`, can optionally be provided as a `string` in inserts and
// can never be updated:
modified_at: ColumnType<Date, string | undefined, never>;
}
interface PetTable {
id: Generated<number>;
name: string;
owner_id: number;
species: 'dog' | 'cat';
}
interface MovieTable {
id: Generated<string>;
stars: number;
}
// Keys of this interface are table names.
interface Database {
person: PersonTable;
pet: PetTable;
movie: MovieTable;
}
Now you can use this type by creating a new pooled Kysely connection. Note: your database connection
string will be automatically retrieved from your environment variables. This uses createPool
from
@vercel/postgres
under the hood.
import { createKyselyPool } from '@vercel/postgres/kysely';
interface Database {
person: PersonTable;
pet: PetTable;
movie: MovieTable;
}
const db = createKyselyPool<Database>();
await db
.insertInto('pet')
.values({ name: 'Catto', species: 'cat', owner_id: id })
.execute();
const person = await db
.selectFrom('person')
.innerJoin('pet', 'pet.owner_id', 'person.id')
.select(['first_name', 'pet.name as pet_name'])
.where('person.id', '=', id)
.executeTakeFirst();
For more information on using Kysely, checkout the docs: https://github.com/kysely-org/kysely
When using the createClient
or createPool
functions, you can pass in additional options alongside the connection string that conforms to VercelPostgresClientConfig
or VercelPostgresPoolConfig
.
FAQs
An @vercel/postgres wrapper for the kysely ORM
The npm package @vercel/postgres-kysely receives a total of 2,610 weekly downloads. As such, @vercel/postgres-kysely popularity was classified as popular.
We found that @vercel/postgres-kysely demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.