@ducquang/zenith-adapter-sequelize
v0.1.1
Published
Sequelize adapter for @zenith/core — adds MySQL/PostgreSQL/SQLite quota persistence.
Maintainers
Readme
@ducquang/zenith-adapter-sequelize
📖 Overview
@ducquang/zenith-adapter-sequelize is the official database persistence adapter for the Zenith AI Framework. It extends the @ducquang/zenith-core engine by seamlessly integrating Sequelize, allowing you to track AI usage quotas, rate limits, and resource consumption across your user base using relational databases.
✨ Features
- 💾 Multi-Database Support: Works out of the box with major relational databases.
- 📊 Quota Persistence: Accurately track and deduct AI tokens or complexity weights per tenant/user in your database.
- 🔌 Plug-and-Play Integration: Designed to inject directly into the Zenith Core lifecycle.
- 🛡️ Transaction Safe: Ensures atomic quota deductions to prevent race conditions.
✅ Tested & Verified Dialects
| Dialect | Tested Driver | Status |
| :--- | :--- | :--- |
| MySQL | mysql2 | Supported |
| PostgreSQL | pg | Supported |
| SQLite | sqlite3 | Supported |
| MariaDB | mariadb | Supported |
📦 Installation
Install both the adapter and its peer dependency (the core engine):
npm install @ducquang/zenith-core @ducquang/zenith-adapter-sequelizeNote: You must also install sequelize and the appropriate database driver (e.g., mysql2, pg, sqlite3).
npm install sequelize mysql2🚀 Basic Usage
import { AIOrchestrator } from '@ducquang/zenith-core';
import { SequelizeAdapter } from '@ducquang/zenith-adapter-sequelize';
import { Sequelize } from 'sequelize';
// 1. Initialize your Sequelize instance
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'mysql'
});
// 2. Initialize the Adapter
const adapter = new SequelizeAdapter(sequelize);
// 3. Inject the adapter into the Zenith Core Engine
const ai = new AIOrchestrator({
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
adapter: adapter
});
// The orchestrator will now automatically use the Sequelize adapter
// to verify and deduct quotas when AI requests are made.🤝 Contributing
If you'd like to support more dialects or improve the adapter's efficiency, please feel free to submit a PR!
📜 License
AGPL-3.0 License
