2.6.0 • Published 5 months ago

gscb-db v2.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

GSCB-DB Library

A database library for GitSense Chat Bridge (GSCB) that provides a clean and type-safe interface for database operations.

Installation

npm install gscb-db

Usage

import { DatabaseClient, DatabaseConfig } from 'gscb-db';

// Configure the database
const config: DatabaseConfig = {
    path: './data.db',
    poolSize: 5,
    timeout: 5000,
    verbose: false
};

// Create and initialize the client
const client = new DatabaseClient(config);
await client.initialize();

// Use the services
const groupId = await client.groups.createGroup({
    name: 'My Group',
    type: 'git-repo',
    gitMeta: {
        type: 'repo',
        path: '/path/to/repo',
        bare: false,
        importedAt: new Date().toISOString()
    }
});

// Close the client when done
await client.close();

Features

  • Connection pooling with configurable size and timeout
  • Full TypeScript support with strict typing
  • Comprehensive error handling
  • Transaction support
  • Logging with Winston
  • Schema migrations
  • CRUD operations for all entities:
    • Groups
    • Chats
    • Messages
    • Prompts

API Documentation

DatabaseClient

The main client class that provides access to all services.

const client = new DatabaseClient(config);
await client.initialize();

// Access services
client.groups    // GroupService
client.chats     // ChatService
client.messages  // MessageService
client.prompts   // PromptService

Services

Each service provides CRUD operations for its respective entity:

  • createX: Create a new entity
  • getXById: Get an entity by ID
  • updateX: Update an existing entity
  • deleteX: Delete an entity
  • Additional methods specific to each entity type

Error Handling

The library provides specific error types for different scenarios:

  • GSCBError: Base error class
  • DatabaseError: Database-related errors
  • ConnectionError: Connection issues
  • QueryError: SQL query errors
  • ValidationError: Data validation errors
  • NotFoundError: Resource not found

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

License

MIT

2.6.0

5 months ago

2.5.0

5 months ago

2.4.0

5 months ago