@encoradb/adapters
v0.1.1
Published
Plug-and-play database adapters for **EncoraDB**. Verify seamless integration with your favorite SQL drivers and ORMs.
Maintainers
Readme
@encoradb/adapters
Plug-and-play database adapters for EncoraDB. Verify seamless integration with your favorite SQL drivers and ORMs.
📦 Installation
pnpm add @encoradb/adapters @encoradb/core🐘 Slonik Adapter
The Slonik adapter uses interceptors to automatically decrypt data as it is fetched from the database.
Usage
import { createPool } from "slonik";
import { EncoraDB } from "@encoradb/core";
import { createEncoraInterceptor } from "@encoradb/adapters";
// 1. Initialize EncoraDB Core
const encora = new EncoraDB({
masterKey: "...",
mode: "local",
encryptColumns: {
users: ["email"],
},
});
// 2. Create the Interceptor
const encoraInterceptor = createEncoraInterceptor(encora);
// 3. Add to Slonik Pool
const pool = await createPool("postgres://...", {
interceptors: [encoraInterceptor],
});
// 4. Query!
// Automatic Decryption happens on SELECT
const user = await pool.one(sql.type(User)`SELECT * FROM users WHERE id = 1`);
console.log(user.email); // Decrypted!Handling Joins
For JOINs, where column names might collide, use the table__column alias convention. The adapter automatically detects this format and decrypts using the correct table context.
const result = await pool.any(sql.type(Result)`
SELECT
users.id,
users.email as users__email, -- Aliased for auto-decryption
orders.id as order_id
FROM users
JOIN orders ON ...
`);🔜 Upcoming Adapters
- Prisma Middleware
- Knex Hooks
- Hibernate / TypeORM
📄 License
MIT
