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.
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.
npm install @prisma-idb/idb-client-generator
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
}
Run the Prisma client generation command:
npx prisma generate
This will generate a client in your project.
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);
}
The API mimics Prisma Client's API for ease of use:
Insert a new record:
idbClient.modelName.create({
data: {
field: value,
},
});
Retrieve all records:
idbClient.modelName.findMany();
Retrieve a single record by unique key:
idbClient.modelName.findUnique({
where: { key: value },
});
Update a record:
idbClient.modelName.update({
where: { key: value },
data: { key: newValue },
});
Delete a record:
idbClient.modelName.delete({
where: { key: value },
});
- IndexedDB Dependency: The client internally uses the
idb
library for IndexedDB operations. - Compatibility: Ensure your environment supports IndexedDB (modern browsers).
- Local-Only: This is designed for local storage scenarios and does not support server-side databases.
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.