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

@zthun/dalmart-db

v1.6.14

Published

A set of interfaces and option builders for database manipulation.

Downloads

88

Readme

Dalmart Database

This is the core package of the Dalmart system. It contains the common database interfaces, collection declarations, and options builders used by the backend implementations. It does not connect to a database on its own.

Installation

Install with npm or Yarn:

npm install @zthun/dalmart-db
yarn add @zthun/dalmart-db

Document Database

Document databases store documents, usually as JSON-like objects with key-value pairs. MongoDB is one example of a document database.

Dalmart's document database interface defines create, read, update, delete, and count operations with bulk operations in mind. To insert one document, pass an array containing one item; to insert many documents, pass a larger array. Updates and deletes apply to all documents matching an optional filter and return the number of documents affected. Omitting the filter updates or deletes all documents in the collection.

Dalmart uses request, filter, and sort types from @zthun/helpful-query to provide a common API across implementations. Reads accept a data request for filtering, sorting, and pagination; counts accept a filter. Backend capabilities can differ: MongoDB supports collection joins, while the JSON folder implementation does not.

Document Database Example

import type { IZDatabaseDocument } from "@zthun/dalmart-db";
import type { IZDataRequest, IZFilter, IZPage } from "@zthun/helpful-query";
import {
  ZDataRequestBuilder,
  ZFilterBinaryBuilder,
  ZPageBuilder,
} from "@zthun/helpful-query";

interface IZPokemon {
  _id?: string;
  name: string;
}

export class PokemonService {
  public static readonly Collection = "Pokemon";

  public constructor(private _dal: IZDatabaseDocument) {}

  public async list(req: IZDataRequest): Promise<IZPage<IZPokemon>> {
    const count = await this._dal.count(PokemonService.Collection, req.filter);
    const data = await this._dal.read<IZPokemon>(
      PokemonService.Collection,
      req,
    );
    return new ZPageBuilder().count(count).data(data).build();
  }

  public async get(id: string): Promise<IZPokemon | undefined> {
    const byId = new ZFilterBinaryBuilder()
      .subject("_id")
      .equal()
      .value(id)
      .build();
    const req = new ZDataRequestBuilder().page(1).size(1).filter(byId).build();
    const [result] = await this._dal.read<IZPokemon>(
      PokemonService.Collection,
      req,
    );
    return result;
  }

  public async create(template: IZPokemon): Promise<IZPokemon> {
    // Dalmart always operates with bulk in mind.
    const [result] = await this._dal.create(PokemonService.Collection, [
      template,
    ]);
    return result;
  }

  public async createAll(templates: IZPokemon[]): Promise<IZPokemon[]> {
    return this._dal.create(PokemonService.Collection, templates);
  }

  public update(template: Partial<IZPokemon>, filter: IZFilter) {
    // Everything matching the filter will be updated with the fields in the partial template.
    return this._dal.update(PokemonService.Collection, template, filter);
  }

  public async delete(id: string): Promise<number> {
    const byId = new ZFilterBinaryBuilder()
      .subject("_id")
      .equal()
      .value(id)
      .build();
    return this._dal.delete(PokemonService.Collection, byId);
  }

  public async purge(): Promise<number> {
    // Deletes all documents in the collection.
    return this._dal.delete(PokemonService.Collection);
  }
}

Memory Database

The IZDatabaseMemory interface represents key-value storage, including Redis, browser local and session storage, localForage, and JSON files. Despite the name, these implementations are not all limited to in-memory storage.

This interface provides read, upsert, and delete operations rather than queries. A read returns null when the key does not exist. You can supply a fallback value; whether that fallback is persisted depends on the implementation. Deleting without a key clears all keys in the underlying store.

Memory Database Example

import type { IZDatabaseMemory } from "@zthun/dalmart-db";

interface IZPokemon {
  _id?: string;
  name: string;
}

export class PokemonCache {
  public constructor(private _dal: IZDatabaseMemory) {}

  public async read(
    id: string,
    retrieve: () => Promise<IZPokemon>,
  ): Promise<IZPokemon> {
    const result = await this._dal.read<IZPokemon>(id);

    if (result != null) {
      return result;
    }

    const value = await retrieve();
    return this.update(id, value);
  }

  public update(key: string, value: IZPokemon): Promise<IZPokemon> {
    return this._dal.upsert(key, value);
  }

  public async bust(id: string): Promise<void> {
    await this._dal.delete(id);
  }
}

Relational Databases

Dalmart currently supports document and key-value databases. It does not provide a relational database interface or implementation.