Generate types for idb from prisma schema
npm install @prisma-idb/idb-client-generatorThis 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
This library is not fully ready yet. Check issue #52 for the current list of implemented 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.
``bash`
npm install @prisma-idb/idb-client-generator
Update your prisma.schema file to include the generator:
`prisma
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
}
`
Run the Prisma client generation command:
`bash`
npx prisma generate
This will generate a client in your project.
Import the generated client and use it in your code:
`typescript
import { PrismaIDBClient } from "./outputPath/prisma-idb-client";
async function main() {
const idbClient = await PrismaIDBClient.createClient();
await idbClient.user.create({
data: { name: "Alice", email: "alice@example.com" },
});
const users = await idbClient.user.findMany();
console.log(users);
}
`
The API mimics Prisma Client's API for ease of use:
Insert a new record:
`javascript`
idbClient.modelName.create({
data: {
field: value,
},
});
Retrieve all records:
`javascript`
idbClient.modelName.findMany();
Retrieve a single record by unique key:
`javascript`
idbClient.modelName.findUnique({
where: { key: value },
});
Update a record:
`javascript`
idbClient.modelName.update({
where: { key: value },
data: { key: newValue },
});
Delete a record:
`javascript``
idbClient.modelName.delete({
where: { key: value },
});
- 📖 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
We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to contribute to this project.
If you discover a security vulnerability, please follow our SECURITY.md guidelines on reporting issues responsibly.
This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for more details.
Special thanks to the open-source community for their contributions to the tools and libraries used in this project.