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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sawmaxxx/aerospike-orm

v1.0.44

Published

aerospike orm (actually is odm) package thats include most operation as simple powered by udf for nestjs

Readme

Project Title

Aerospike orm that make easy to use aerospike db for all developers , let you use most operation of common databaes with udf power;

NestJS Aerospike ORM

npm downloads license

A fully-featured Aerospike ORM (Actually ODM) module for NestJS, providing convenient services to:

  • Interact with Aerospike clusters
  • Create secondary indexes
  • Perform scans and queries
  • Apply filtering, sorting, aggregation, and pagination
  • Handle nested objects and arrays
  • Manage TTL (default ttl is infinty that let you persist data), durable deletes, and upserts
  • Automatically register UDF scripts

Works with TypeScript, NestJS, and both Community Edition (CE) and Enterprise Edition (EE) of Aerospike.

Table of Contents


Installation

npm install @sawmaxxx/aerospike-orm
# or using yarn
yarn add @sawmaxxx/aerospike-orm

Environment Variables

AEROSPIKE_HOST=127.0.0.1:3000
AEROSPIKE_NAME_SPACE=test
AERO_VERSION_TYPE=ce # or ee for enterprise edition
AEROSPIKE_MAX_CONNECTION=300

Usage

Import the Module

import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { AerospikeModule } from "@sawmaxxx/aerospike-orm";

import { ConfigModule } from "@nestjs/config";
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: [".env"],
      cache: true,
    }),
    AerospikeModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Inject the Service

import { Injectable } from "@nestjs/common";
import { AerospikeService } from "@sawmaxxx/aerospike-orm";

@Injectable()
export class UserService {
  constructor(private readonly aerospikeService: AerospikeService) {}

  async getUser(userId: string) {
    return this.aerospikeService.get("users", userId);
  }

  async createUser(user: any) {
    return this.aerospikeService.put("users", user, user.id, {
      generateTimeStamps: true,
    });
  }
}

Service Methods

| Method | Description | | ------------------------------------------------------------------------------ | -------------------------------------- | | get<T>(set: string, key: string): Promise<T> | Retrieve a record by key | | put<T>(set: string, inputBin: Partial<T>, key: string, options?): Promise<T> | Upsert a record | | delete<T>(set: string, key: string, durableDelete?: boolean) | Delete a record | | getAll<T>(set: string, options?): Promise<{results: T[], total?: number}> | Retrieve multiple records with filters | | createSecondaryIndex<T>(params): Promise<void> | Create secondary index | | operateWithSingleKey<T>(set: string, key: string, operations: any[]) | Perform operations on a key | | countAll(set: string, filters, options, filterProccessType) | Count records in a set |


Enums

  • IndexDataTypes - BLOB, STRING, INTEGER, GEO2DSPHERE, OBJECT
  • IndexTypes - DEFAULT, LIST, MAPKEYS, MAPVALUES
  • FilterOperations - EQUAL, RANGE, CONTAINS, LIKE, EQUAL_MAP_VALUE, CONTAINS_ARRAY, CONTAINS_MAP_VALUE
  • RecordExistsActions - IGNORE, CREATE, UPDATE, REPLACE, CREATE_OR_REPLACE
  • AggreagteOperations - SUM, COUNT, AVG, MAX, MIN
  • SortTypes - ASC, DESC

Utilities

  • generateObjectId() - Generates unique ObjectId
  • aerospikeWhereChecker(where, record) - Checks if a record satisfies a where condition

UDF Scripts

  • filter_query.lua - Used for complex query filtering
  • order_by_query.lua - Used for ordering results

UDFs are automatically registered on module initialization.


Examples

// Get all records sorted by createdAt descending
const users = await this.aerospikeService.getAll<UserModel>("users", {
  sort: { binName: "createdAt", type: SortTypes.DESC },
  filterType: "and",
  pageIndex: 10,
  pageNumber: 1,
  returnTotal: true,
  //just use excludeBins option if that actually needed , its a bit make bad effect on speed also on high page index
  excludeBins: {
    bins: [
      "age",
    ]
  },

  skipSorting: false,
  secondaryIndexOption: { indexes : [
    {
       binName: "name",
       indexType: IndexTypes.DEFAULT,
       value: "john"
       filterOperation: FilterOperations.EQUAL ,
   }
  ]
  },
});

// Upsert a key
await this.aerospikeService.put<UserModel>("users", { name: "John Doe" }, "user_123", {
  generateTimeStamps: true,
  returnDoc: true,
  generateIdForArrayKeys: false,
  writePolicy: { exists: RecordExistsActions.IGNORE },
});

// Create secondary index
await this.aerospikeService.createSecondaryIndex({
  set: "users",
  binName: "name",
  indexDataType: IndexDataTypes.STRING,
  indexType: IndexTypes.DEFAULT,
  indexName: "users_index_name:v:1.1",
});

//Operate with single key (atomic operation)
await this.aerospikeService.operateWithSingleKey(
  "users",
  "user_123",
  [
    _aerospike.default.lists.append("profiles", {
      "user_123",
      meta: {
        bin: {name : "example"}
      },
    }),
  ],
  [
    //another op
  ]
);

//Aggreagte operations
 const userAnalytics = await this.aerospikeService.getAll<UserModel>(
      "users",
      {
        pageIndex: 100
        pageNumber: 1,
        returnTotal: false,
        hybridFilter: false,
        skipSorting: false,
        secondaryIndexOption: { indexes },
        groupBy: {
          groupByBinName: "eventName",
          aggregateBinName: "_id",
          aggreateOperation: AggreagteOperations.COUNT,
        },
      }
);

// Delete a key
await this.aerospikeService.delete("users", "user_123");

Contributing

  1. Fork the repository
  2. Create a branch (git checkout -b feature-name)
  3. Make your changes
  4. Submit a pull request

License

This project is licensed under the AGPL-3.0 License.