npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gitsense/gscb-db

v0.4.0

Published

Database library for GitSense Chat Bridge (GSCB)

Readme

GSCB-DB Library

A database library for GitSense Chat Bridge (GSCB) that provides a clean and type-safe interface for database operations. Built on better-sqlite3 for high performance and concurrency.

Installation

npm install gscb-db

Usage

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

// Configure the database
const config: DatabaseConfig = {
    path: './data.db',
    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',
    meta: {
        type: 'repo',
        path: '/path/to/repo',
        bare: false,
        importedAt: new Date().toISOString()
    }
});

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

Features

  • WAL Mode: Write-Ahead Logging enabled by default for improved concurrency and performance
  • Synchronous Core: Built on better-sqlite3 for optimal performance with a backwards-compatible async API
  • 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

constructor(config: DatabaseConfig)

Creates a new DatabaseClient instance.

  • config: A DatabaseConfig object containing the database path and verbose settings.

async initialize(): Promise<void>

Initializes the database connection and runs migrations. Must be called before any other operations.

async close(): Promise<void>

Closes the database connection.

isInitialized(): boolean

Returns true if the database client has been initialized, false otherwise.


Direct Database Access

For advanced users, the database property provides direct access to the underlying database methods. Use this with caution, as it bypasses the service layer's validation and business logic.

Warning: Direct database access should only be used when the standard API methods are insufficient. Always handle validation and error checking manually.

database.transaction<T>(callback: () => T): Promise<T>

Executes a transaction with the provided callback.

  • callback: The function to execute within the transaction. Note: While the method returns a Promise for compatibility, the callback itself is executed synchronously.
  • Returns: The result of the callback.

database.run(sql: string, params?: any[]): void

Executes a SQL query.

  • sql: The SQL query to execute.
  • params: Optional parameters for the query.

database.get<T>(sql: string, params?: any[]): T | undefined

Executes a SQL query and returns a single row.

  • sql: The SQL query to execute.
  • params: Optional parameters for the query.
  • Returns: The first row of the result set.

database.all<T>(sql: string, params?: any[]): T[]

Executes a SQL query and returns all rows.

  • sql: The SQL query to execute.
  • params: Optional parameters for the query.
  • Returns: All rows of the result set.

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