npm package: @geenius/db
Description: Geenius DB — Multi-provider database adapter implementations (Convex, Supabase, Neon, MongoDB, CloudflareKV)
Author: Antigravity HQ
Latest version: 0.2.1

# `@geenius/db`

> Multi-provider database adapter implementations for the Geenius ecosystem.

---

## Overview

`@geenius/db` provides real database provider implementations that conform to the `DbAdapter` interface from `@geenius/adapters-shared`. This is the package you use when you need to connect to an actual database.

### Providers

| Provider | Factory | SDK |
|----------|---------|-----|
| **Convex** | `createConvexDbAdapter()` | `convex` |
| **Supabase** | `createSupabaseDbAdapter()` | `@supabase/supabase-js` |
| **Neon (Drizzle)** | `createNeonDbAdapter()` | `@neondatabase/serverless` + `drizzle-orm` |
| **MongoDB** | `createMongoDbAdapter()` | `mongodb` |
| **Cloudflare KV** | `createCloudflareKVDbAdapter()` | `@cloudflare/workers-types` |
| **In-Memory** | `createMemoryDbAdapter()` | *(none)* |

> For localStorage-based prototyping (Pronto tier), use `createLocalStorageDbAdapter()` from `@geenius/adapters`.

---

## Installation

```bash
pnpm add @geenius/db
```

## Sub-package Exports

```typescript
import { createConvexDbAdapter, createSupabaseDbAdapter } from '@geenius/db'          // shared
import { DbProvider, useDb }                                from '@geenius/db/react'   // React hooks
import { DbProvider, createDb }                             from '@geenius/db/solidjs' // SolidJS primitives
```

---

## Quick Start

### Convex

```typescript
import { createConvexDbAdapter } from '@geenius/db'

const db = createConvexDbAdapter({
  client: convexClient,
  functions: {
    create: api.adapters.create,
    get: api.adapters.get,
    update: api.adapters.update,
    delete: api.adapters.delete,
    list: api.adapters.list,
    query: api.adapters.query,
    count: api.adapters.count,
  },
})
```

### Supabase

```typescript
import { createSupabaseDbAdapter } from '@geenius/db'

const db = createSupabaseDbAdapter({
  supabaseUrl: process.env.SUPABASE_URL!,
  supabaseKey: process.env.SUPABASE_ANON_KEY!,
})
```

### Neon (Drizzle)

```typescript
import { createNeonDbAdapter } from '@geenius/db'
import { eq, and, gt, like } from 'drizzle-orm'

const db = createNeonDbAdapter({
  connectionString: process.env.DATABASE_URL!,
  schema: myDrizzleSchema,
  operators: { eq, and, gt, like, or, ne, lt, lte, gte, sql },
})
```

### MongoDB

```typescript
import { createMongoDbAdapter } from '@geenius/db'

const db = createMongoDbAdapter({
  uri: process.env.MONGODB_URI!,
  dbName: 'my-app',
})
```

### React Provider

```tsx
import { DbProvider, useDb } from '@geenius/db/react'
import { createConvexDbAdapter } from '@geenius/db'

function App() {
  const db = createConvexDbAdapter({ ... })
  return (
    <DbProvider adapter={db}>
      <MyComponent />
    </DbProvider>
  )
}

function MyComponent() {
  const db = useDb()
  // db.list('users'), db.create('users', { name: '...' }), etc.
}
```

### SolidJS Provider

```tsx
import { DbProvider, createDb } from '@geenius/db/solidjs'
import { createConvexDbAdapter } from '@geenius/db'

function App() {
  const db = createConvexDbAdapter({ ... })
  return (
    <DbProvider adapter={db}>
      <MyComponent />
    </DbProvider>
  )
}

function MyComponent() {
  const db = createDb()
  // db.list('users'), db.create('users', { name: '...' }), etc.
}
```

---

## Architecture

This package implements the `DbAdapter` interface defined in `@geenius/adapters-shared`:

```typescript
interface DbAdapter {
  create<T>(collection: string, data: Omit<T, 'id'>): Promise<T & { id: string }>
  get<T>(collection: string, id: string): Promise<T | null>
  update<T>(collection: string, id: string, data: Partial<T>): Promise<T | null>
  delete(collection: string, id: string): Promise<boolean>
  list<T>(collection: string, options?: ListOptions): Promise<T[]>
  query<T>(collection: string, filter: QueryFilter): Promise<T[]>
  count(collection: string, filter?: QueryFilter): Promise<number>
}
```

All providers throw `DbError` from `@geenius/adapters-shared` on failure.

---

## License

MIT — © Antigravity HQ