Npm
npm
yarn
pnpm
bun
npm i drizzle-orm
npm
yarn
pnpm
bun
npm i drizzle-orm -D drizzle-kit
AnchorCards
Callout
Callout example
Callout example
Callout example
IMPORTANT
Callout example
WARNING
Callout example
CodeTabs with CodeTab
index.ts
schema.ts
import * as schema from './schema';
import { drizzle } from 'drizzle-orm/...';
const db = drizzle(client, { schema });
const result = await db.query.users.findMany({
with: {
posts: true
},
});
[{
id: 10,
name: "Dan",
posts: [
{
id: 1,
content: "SQL is awesome",
authorId: 10,
},
{
id: 2,
content: "But check relational queries",
authorId: 10,
}
]
}]
IsSupportedChipGroup
PostgreSQL
SQLite
MySQL
Section
For codeblocks connection
import { sql } from "drizzle-orm";
import { integer, sqliteTable } from "drizzle-orm/sqlite-core";
const table = sqliteTable('table', {
int1: integer('int1').default(42),
int2: integer('int2').default(sql`(abs(42))`)
});
CREATE TABLE `table` (
`int1` integer DEFAULT 42
`int2` integer DEFAULT (abs(42))
);
Tabs with Tab and Section
import { sql } from "drizzle-orm";
import { integer, uuid, pgTable } from "drizzle-orm/pg-core";
const table = pgTable('table', {
integer1: integer('integer1').default(42),
integer2: integer('integer2').default(sql`'42'::integer`),
uuid1: uuid('uuid1').defaultRandom(),
uuid2: uuid('uuid2').default(sql`gen_random_uuid()`),
});
CREATE TABLE IF NOT EXISTS "table" (
"integer1" integer DEFAULT 42,
"integer2" integer DEFAULT '42'::integer,
"uuid1" uuid DEFAULT gen_random_uuid(),
"uuid2" uuid DEFAULT gen_random_uuid()
);
SimpleLinkCards
Steps
With h4 headers
Install babel plugin
It’s necessary to bundle SQL migration files as string directly to your bundle.
npm install babel-plugin-inline-import
Update config files.
You will need to update babel.config.js
, metro.config.js
and drizzle.config.ts
files
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
plugins: [["inline-import", { extensions: [".sql"] }]], // <-- add this
};
};
YoutubeCards
Collapsable code block
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Product {
id Int @id @default(autoincrement())
name String
supplierId Int
unitPrice Decimal @db.Decimal(10, 4)
unitsInStock Int
supplier Supplier? @relation(fields: [supplierId], references: [id])
orderDetails OrderDetail[]
@@map("products")
}
model Supplier {
id Int @id @default(autoincrement())
companyName String
city String
country String
products Product[]
@@map("suppliers")
}
model OrderDetail {
orderId Int
productId Int
quantity Int
order Order @relation(fields: [orderId], references: [id])
product Product @relation(fields: [productId], references: [id])
@@id([orderId, productId])
@@map("order_details")
}
model Order {
id Int @id @default(autoincrement())
orderDate DateTime @db.Date
shippedDate DateTime? @db.Date
shipAddress String
shipPostalCode String?
shipCountry String
orderDetails OrderDetail[]
@@map("orders")
}