Encrypted columns for Drizzle, with masked reads by default.
SaaS apps end up storing other people's credentials: OAuth refresh tokens, API keys, webhook secrets. They belong encrypted at rest, and they should never show up in a log line, an API response, or a JSON dump of a row.
Drizzle Secrets is a column type. Declare a column with secret() and values are encrypted with AES-256-GCM on write. Reads return a masked value by default, or a SecretValue wrapper that only gives up the plaintext through an explicit expose() call.
Every ciphertext carries the ID of the key that encrypted it, so you can add a new key, keep decrypting with the old ones, and rotate rows when you are ready. Plaintext rows already in the table are still readable, so you can turn on encryption without a big-bang migration.
const secret = createDrizzleSecret(process.env.ENCRYPTION_KEY!)
export const integrations = pgTable('integrations', {
id: text('id').primaryKey(),
apiKey: secret('api_key'), // reads as '••••1234'
refreshToken: secret('refresh_token', { mode: 'decrypt' }),
})
const [row] = await db.select().from(integrations)
console.log(row.refreshToken) // SecretValue(••••9f2c)
const token = expose(row.refreshToken)Version
0.2.0
Category
Data
Downloads
503 weekly
Last updated
5 days ago