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

@thorbens/database

v1.0.0-alpha.25

Published

Database interface and common implementations.

Readme

Description

This repository provides a common description for database operations (CRUD). The code is writte in in Typescript and transpiled against the node 14 LTS features set.

  1. Documentation
  2. Usage
  3. Recommended Usage
  4. Common Database
  5. Implementations

Documentation

The generate typedoc documentation can be found here.

Usage

A database implementation should implement the abstract Database class.

import {Database} from "@thorbens/database";

class MyDatabase implements Database {
...
}

To perform CRUD operations, a Repository should be used. Therefore, a model should be defined:

class MyDatabaseModel extends DatabaseModel {
  foo: string;
}

Performing a query against the repository:

// create a new database instance
const database = new MyDatabase();
// depending on implementation, connect may be called before any operation
await database.connect();
// retrieve the repository for your model
const repository = database.getRepository(MyDatabaseModel);
// create a query to perform a complex request
const query = repository.createQuery();
// retrieve the condition builder for building conditions
const conditionBuilder = database.getConditionBuilder<MyDatabaseModel>();
// create a simple equal operator
const equalOperator = conditionBuilder.createEqualOperator(
  "foo",
  "bar"
);
// add the operator the the query
query.addCondition(equalOperator);

// execute the query
const result = await repository.findByQuery(query);

Recommended use for retrieving a database instance

Invoke a database via typescript-ioc:

import { Container, Scope } from "typescript-ioc";
import { Database } from "@thorbens/database";

// bind your database implementation to the database
Container.bind(Database).to(MyDatabase).scope(Scope.Singleton);

And inject it in your services:

import {Inject} from "typescript-ioc";
import {Database} from "@thorbens/database";

class DatabaseService {
    private readonly database: Database;

    public constructor(
        @Inject database: Database,
        ...
    ) {
        this.database = database;
    }
}

CommonDatabase

The CommonDatabase package provides an abstraction for database operations. To create conditions for an unknown database, the CommonDatabaseConditionBuilder can be used. A DatabaseConditionParser is able to parse CommonDatabaseOperatorObjects for the implemented database.

CommonDatabaseConditionBuilder & DatabaseConditionParser

CommonDatabaseConditionBuilder provides functionality to build database conditions such as logical conditions (e.g. or condition) and atom conditions (e.g. equal condition). This might be useful to send complex dynamic database queries generated by a client to a backend service:

Example:

import {CommonDatabaseConditionBuilder} from "@thorbens/database";

// build a condition in your client
const conditionBuilder = new CommonDatabaseConditionBuilder<MyDatabaseModel>();
const value = "foo";
const key = "bar";
const operator = conditionBuilder.createEqualOperator(key, value);
const commonObject = operator.toCommonObject();

// send the common object to a receiver (e.g. a backend service)
...

// use it with your database
const receivedCommonObject = ...
const myDatabase = new MyDatabase();
const parsedCondition = myDatabase.getConditionParser().parse(receivedCommonObject);
if (!parsedCondition) {
    // error handling
}
const query = myDatabase.createQuery<MyDatabaseModel>();
query.addCondition(parsedCondition);
...

Implementations

| Database | Repository | | ------------- | -------------------------------------------- | | MongoDb | https://gitlab.com/thorbens/mongodb-database | | ElasticSearch | tbd. |