index.ts overview
Drizzle ORM stores for effect-auth on PostgreSQL, SQLite or MySQL, one namespace per module. Each store is a namespace with make and layer, and Layers.layer provides them together; Pg, Sqlite and MySql hold each dialect’s tables and DDL; Columns.defineSchema maps the stores onto an application’s tables; Requests, LadderCheck and OwnedListFilter complete it.
Example
import { Effect, Layer } from "effect";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as Drizzle from "@thomasfosterau/effect-auth-drizzle";
const db = drizzle({ client: new Pool({ connectionString: process.env["DATABASE_URL"] }) });
// All three stores on top of the drizzle handle.
const stores = Drizzle.Layers.layer().pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
// Custom table names use the same schema shape.
const custom = Drizzle.Pg.defineTables({ sessions: "app_sessions" });
const customStores = Drizzle.Layers.layer(custom).pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
// Another dialect: the same stores, that dialect's tables.
const sqliteStores = Drizzle.Layers.layer(Drizzle.Sqlite.tables).pipe(
Layer.provide(Drizzle.Database.databaseLayer(sqliteDb)),
);
// Batched reads for application code (one query per batch of lookups).
const requests = Drizzle.Requests.layer().pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
const users = Effect.forEach(ids, Drizzle.Requests.getUser, { concurrency: "unbounded" });
// A drizzle Effect driver: the stores run its queries directly, no Promise
// boundary anywhere between `Auth.SessionStore` and the database.
import * as PgDrizzle from "drizzle-orm/effect-postgres";
const effectStores = Drizzle.Layers.layer().pipe(
Layer.provide(Drizzle.Database.effectDatabaseLayer(PgDrizzle.makeWithDefaults())),
);
// A handle the application owns the lifetime of: passing an `Effect` instead
// of a handle resolves it per query, in the calling request's scope.
const perRequest = Drizzle.Layers.layer().pipe(Layer.provide(Drizzle.Database.databaseLayer(RequestDatabase)));
// An application's own tables, under its own column names and key types: the
// mapping says where each field the stores need actually lives.
const adopted = Drizzle.Layers.layer(
Drizzle.Columns.defineSchema({
sessions: { table: appSessions, columns: { id: "digest", userId: "account", ... } },
users: { table: appUsers, columns: { id: "key", name: "displayName", ... } },
identifiers: { table: appHandles, columns: { id: "key", type: "kind", ... } },
}),
).pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
Exports Grouped by Category
- utils
- ApiKeyStore (namespace export)
- Columns (namespace export)
- Database (namespace export)
- EmailPasswordStore (namespace export)
- IdentifierStore (namespace export)
- LadderCheck (namespace export)
- Layers (namespace export)
- MySql (namespace export)
- OrganizationStore (namespace export)
- OwnedListFilter (namespace export)
- Pg (namespace export)
- RateLimitStore (namespace export)
- Requests (namespace export)
- Schema (namespace export)
- SessionStore (namespace export)
- SingleTableIdentifierStore (namespace export)
- Sqlite (namespace export)
- TokenStore (namespace export)
- UserServiceStore (namespace export)
- UserStore (namespace export)
utils
ApiKeyStore (namespace export)
Re-exports all named exports from the “./ApiKeyStore.ts” module as ApiKeyStore.
Example
import { Effect, Layer } from "effect";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as Drizzle from "@thomasfosterau/effect-auth-drizzle";
const db = drizzle({ client: new Pool({ connectionString: process.env["DATABASE_URL"] }) });
// All three stores on top of the drizzle handle.
const stores = Drizzle.Layers.layer().pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
// Custom table names use the same schema shape.
const custom = Drizzle.Pg.defineTables({ sessions: "app_sessions" });
const customStores = Drizzle.Layers.layer(custom).pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
// Another dialect: the same stores, that dialect's tables.
const sqliteStores = Drizzle.Layers.layer(Drizzle.Sqlite.tables).pipe(
Layer.provide(Drizzle.Database.databaseLayer(sqliteDb)),
);
// Batched reads for application code (one query per batch of lookups).
const requests = Drizzle.Requests.layer().pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
const users = Effect.forEach(ids, Drizzle.Requests.getUser, { concurrency: "unbounded" });
// A drizzle Effect driver: the stores run its queries directly, no Promise
// boundary anywhere between `Auth.SessionStore` and the database.
import * as PgDrizzle from "drizzle-orm/effect-postgres";
const effectStores = Drizzle.Layers.layer().pipe(
Layer.provide(Drizzle.Database.effectDatabaseLayer(PgDrizzle.makeWithDefaults())),
);
// A handle the application owns the lifetime of: passing an `Effect` instead
// of a handle resolves it per query, in the calling request's scope.
const perRequest = Drizzle.Layers.layer().pipe(Layer.provide(Drizzle.Database.databaseLayer(RequestDatabase)));
// An application's own tables, under its own column names and key types: the
// mapping says where each field the stores need actually lives.
const adopted = Drizzle.Layers.layer(
Drizzle.Columns.defineSchema({
sessions: { table: appSessions, columns: { id: "digest", userId: "account", ... } },
users: { table: appUsers, columns: { id: "key", name: "displayName", ... } },
identifiers: { table: appHandles, columns: { id: "key", type: "kind", ... } },
}),
).pipe(Layer.provide(Drizzle.Database.databaseLayer(db)));
Signature
export * as ApiKeyStore from "./ApiKeyStore.ts"
Columns (namespace export)
Re-exports all named exports from the “./Columns.ts” module as Columns.
Signature
export * as Columns from "./Columns.ts"
Database (namespace export)
Re-exports all named exports from the “./Database.ts” module as Database.
Signature
export * as Database from "./Database.ts"
EmailPasswordStore (namespace export)
Re-exports all named exports from the “./EmailPasswordStore.ts” module as EmailPasswordStore.
Signature
export * as EmailPasswordStore from "./EmailPasswordStore.ts"
IdentifierStore (namespace export)
Re-exports all named exports from the “./IdentifierStore.ts” module as IdentifierStore.
Signature
export * as IdentifierStore from "./IdentifierStore.ts"
LadderCheck (namespace export)
Re-exports all named exports from the “./LadderCheck.ts” module as LadderCheck.
Signature
export * as LadderCheck from "./LadderCheck.ts"
Layers (namespace export)
Re-exports all named exports from the “./Layers.ts” module as Layers.
Signature
export * as Layers from "./Layers.ts"
MySql (namespace export)
Re-exports all named exports from the “./MySqlSchema.ts” module as MySql.
Signature
export * as MySql from "./MySqlSchema.ts"
OrganizationStore (namespace export)
Re-exports all named exports from the “./OrganizationStore.ts” module as OrganizationStore.
Signature
export * as OrganizationStore from "./OrganizationStore.ts"
OwnedListFilter (namespace export)
Re-exports all named exports from the “./OwnedListFilter.ts” module as OwnedListFilter.
Signature
export * as OwnedListFilter from "./OwnedListFilter.ts"
Pg (namespace export)
Re-exports all named exports from the “./PgSchema.ts” module as Pg.
Signature
export * as Pg from "./PgSchema.ts"
RateLimitStore (namespace export)
Re-exports all named exports from the “./RateLimitStore.ts” module as RateLimitStore.
Signature
export * as RateLimitStore from "./RateLimitStore.ts"
Requests (namespace export)
Re-exports all named exports from the “./Requests.ts” module as Requests.
Signature
export * as Requests from "./Requests.ts"
Schema (namespace export)
Re-exports all named exports from the “./Schema.ts” module as Schema.
Signature
export * as Schema from "./Schema.ts"
SessionStore (namespace export)
Re-exports all named exports from the “./SessionStore.ts” module as SessionStore.
Signature
export * as SessionStore from "./SessionStore.ts"
SingleTableIdentifierStore (namespace export)
Re-exports all named exports from the “./SingleTableIdentifierStore.ts” module as SingleTableIdentifierStore.
Signature
export * as SingleTableIdentifierStore from "./SingleTableIdentifierStore.ts"
Sqlite (namespace export)
Re-exports all named exports from the “./SqliteSchema.ts” module as Sqlite.
Signature
export * as Sqlite from "./SqliteSchema.ts"
TokenStore (namespace export)
Re-exports all named exports from the “./TokenStore.ts” module as TokenStore.
Signature
export * as TokenStore from "./TokenStore.ts"
UserServiceStore (namespace export)
Re-exports all named exports from the “./UserServiceStore.ts” module as UserServiceStore.
Signature
export * as UserServiceStore from "./UserServiceStore.ts"
UserStore (namespace export)
Re-exports all named exports from the “./UserStore.ts” module as UserStore.
Signature
export * as UserStore from "./UserStore.ts"