## Prime IDB

A lightweight and efficient library for managing IndexedDB operations in web browsers. With Prime IDB, you can perform CRUD operations, manage object stores, and handle indexed queries effortlessly. This library simplifies working with IndexedDB while maintaining full flexibility and control.

#### ✨ Features

-  🎯 Create and manage IndexedDB databases and object stores.
-  ⚡ Perform CRUD operations with simple functions.
-  🛠️ Support for indexed queries and conditions.
-  🎭 Full support for all libraries and frameworks.
-  🚀 Pure TypeScript implementation with zero dependencies
-  🎯 Full TypeScript support for better development experience
-  ⏱️ Auto-detect database versions and manage upgrades.

#### 📦 Installation

Install the package using npm:

```bash
npm install idb-prime-ts
```

Or with yarn:

```bash
yarn add idb-prime-ts
```

#### 🚀 Quick Start

##### 1. Open or Create a Database

```typescript
import { getDB } from 'idb-prime-ts';

const db = await getDB({
   dbName: 'MyDatabase',
   dbVersion: 1,
   objectStoreName: 'Users',
   indexes: [{ indexName: 'email', unique: true }],
});
```

##### 2. Add Data

```typescript
import { addToIDB } from 'idb-prime-ts';

await addToIDB({
   dbName: 'MyDatabase',
   objectStoreName: 'Users',
   obj: { name: 'John Doe', email: 'john.doe@example.com' },
});
```

##### 3. Get Data by ID

```typescript
import { getByIdIDB } from 'idb-prime-ts';

const user = await getByIdIDB({
   dbName: 'MyDatabase',
   objectStoreName: 'Users',
   id: 1,
});

console.log(user);
```

##### 4. Query Data by Index

```typescript
import { getByIndexIDB } from 'idb-prime-ts';

const users = await getByIndexIDB({
   dbName: 'MyDatabase',
   objectStoreName: 'Users',
   index: 'email',
   condition: IDBKeyRange.only('john.doe@example.com'),
});

console.log(users);
```

##### 5. Update Data

```typescript
import { updateByIdIDB } from 'idb-prime-ts';

await updateByIdIDB({
   dbName: 'MyDatabase',
   objectStoreName: 'Users',
   id: 1,
   updateItem: { name: 'Jane Doe' },
});
```

##### 6. Delete Data

```typescript
import { delByIdIDB } from 'idb-prime-ts';

await delByIdIDB({
   dbName: 'MyDatabase',
   objectStoreName: 'Users',
   id: 1,
});
```

#### API Reference

##### `getDB(args: primeIDBtype): Promise<IDBDatabase>`

Opens or creates an IndexedDB database.

##### `addToIDB(args: addToIDBT): Promise<any>`

Adds an object to the specified object store.

##### `getByIdIDB(args: getByIdIDBT): Promise<any>`

Retrieves a record by its ID.

##### `getByIndexIDB(args: getByIndexIDBT): Promise<any[]>`

Queries data by index and optional conditions.

##### `updateByIdIDB(args: updateByIdIDBT): Promise<any>`

Updates a record by its ID.

##### `delByIdIDB(args: getByIdIDBT): Promise<any>`

Deletes a record by its ID.

### 📄 License

"This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file or details.

---

Made with ❤️ using TypeScript
