@prisma-idb/idb-client-generator
v0.35.1
Published
Generate types for idb from prisma schema
Readme
Prisma IndexedDB Client Generator
This library is a Prisma generator that creates a client with a similar syntax and behavior to the Prisma Client but is designed to operate with IndexedDB for local storage. It allows developers to interact with IndexedDB using a familiar Prisma-like API.
📖 Documentation • 🚀 Live Demo • 📦 npm Package • 🏗️ Main Repository
⚠️ Warning
This library is not fully ready yet. Check issue #52 for the current list of implemented features.
Features
- Prisma-like syntax and API for IndexedDB.
- Supports CRUD operations with structured data.
- Integrates seamlessly with Prisma workflows.
- Generates a client tailored to your Prisma schema.
Installation
npm install @prisma-idb/idb-client-generatorUsage
1. Add to Prisma Schema
Update your prisma.schema file to include the generator:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
generator prismaIDB {
provider = "idb-client-generator"
output = "./prisma-idb"
}
model User {
id Int @id @default(autoincrement())
name String
email String @unique
}2. Generate the Client
Run the Prisma client generation command:
npx prisma generateThis will generate a client in your project.
3. Use the Client
Import the generated client and use it in your code:
import { PrismaIDBClient } from "./outputPath/prisma-idb-client";
async function main() {
const idbClient = await PrismaIDBClient.createClient();
await idbClient.user.create({
data: { name: "Alice", email: "[email protected]" },
});
const users = await idbClient.user.findMany();
console.log(users);
}API
The API mimics Prisma Client's API for ease of use:
create
Insert a new record:
idbClient.modelName.create({
data: {
field: value,
},
});findMany
Retrieve all records:
idbClient.modelName.findMany();findUnique
Retrieve a single record by unique key:
idbClient.modelName.findUnique({
where: { key: value },
});update
Update a record:
idbClient.modelName.update({
where: { key: value },
data: { key: newValue },
});delete
Delete a record:
idbClient.modelName.delete({
where: { key: value },
});Resources
- 📖 Full Documentation - Complete API reference, sync guides, and schema requirements
- 🚀 Kanban Example - Live demonstration of the sync engine
- 💻 Example Source Code - Full working example with SvelteKit and sync workers
- 🏗️ Main Repository - Source code and issue tracking
- 📦 npm Package - Install from npm registry
Contributing
We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to contribute to this project.
Security
If you discover a security vulnerability, please follow our SECURITY.md guidelines on reporting issues responsibly.
License
This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for more details.
Acknowledgements
Special thanks to the open-source community for their contributions to the tools and libraries used in this project.
