2.6.0 • Published 7 months ago
gscb-db v2.6.0
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-dbUsage
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 // PromptServiceServices
Each service provides CRUD operations for its respective entity:
createX: Create a new entitygetXById: Get an entity by IDupdateX: Update an existing entitydeleteX: Delete an entity- Additional methods specific to each entity type
Error Handling
The library provides specific error types for different scenarios:
GSCBError: Base error classDatabaseError: Database-related errorsConnectionError: Connection issuesQueryError: SQL query errorsValidationError: Data validation errorsNotFoundError: Resource not found
Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
License
MIT