-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
The Cloudflare D1 Adapter has a private constructor and the only way to instantiate it is to call the static create
method. That method internally calls init, which makes a "create table if not exists" query.
This means that simply instantiating the session storage driver would trigger this query - so effectively it pollutes the whole app. Instead, we should run a migration on setup and remove this superfluous query on instantiation.
storages/packages/cloudflare/src/d1.ts
Lines 13 to 30 in 216ee4f
private constructor(db: D1Database, tableName?: string) { | |
this.db = db; | |
this.tableName = tableName ?? defaultTableName; | |
} | |
static async create<T>(db: D1Database, tableName?: string): Promise<D1Adapter<T>> { | |
const adapter = new D1Adapter<T>(db, tableName); | |
await adapter.#init(); | |
return adapter; | |
} | |
async #init() { | |
await this.db | |
.exec(`CREATE TABLE IF NOT EXISTS "${this.tableName}" (key TEXT PRIMARY KEY, value TEXT)`); | |
await this.db | |
.exec(`CREATE INDEX IF NOT EXISTS "IDX_${this.tableName}" ON ${this.tableName} (key)`); | |
} |
Metadata
Metadata
Assignees
Labels
No labels