CipherStash Docs
StackLatestDrizzleFunctions

extractEncryptionSchema

Extract a CipherStash encryption schema from a Drizzle table definition. Inspects columns created with encryptedType and builds the equivalent `encryptedTab...

@cipherstash/stack


Function: extractEncryptionSchema()

function extractEncryptionSchema<T>(table): EncryptedTable<Record<string, EncryptedColumn>> & Record<string, EncryptedColumn>;

Defined in: .tmp-stack/packages/stack/src/drizzle/schema-extraction.ts:26

Extracts an encryption schema from a Drizzle table definition. This function identifies columns created with encryptedType and builds a corresponding EncryptedTable with encryptedColumn definitions.

Type Parameters

T

T extends PgTable<any>

Parameters

table

T

The Drizzle table definition

Returns

EncryptedTable<Record<string, EncryptedColumn>> & Record<string, EncryptedColumn>

A EncryptedTable that can be used with encryption client initialization

Example

const drizzleUsersTable = pgTable('users', {
  email: encryptedType('email', { freeTextSearch: true, equality: true }),
  age: encryptedType('age', { dataType: 'number', orderAndRange: true }),
})

const encryptionSchema = extractEncryptionSchema(drizzleUsersTable)
const client = await createEncryptionClient({ schemas: [encryptionSchema.build()] })

On this page