You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A TypeScript utility library for working with Aerospike using entities and a base repository pattern. Easily map class properties to Aerospike bins and perform CRUD operations
Features
Decorators (@Bin) for defining Aerospike bins on class properties
Base entity (BaseEntity) with automatic serialization/deserialization
Base repository (BaseRepository) with CRUD, batch read, and query support
Supports default values and required fields
Installation
npm i aerospike-orm
Usage example
import{BaseEntity,Bin,BaseRepository}from'aerospike-orm'import{AerospikeBins,ClientasAerospikeClient,exp}from'aerospike'classUserextendsBaseEntity{
@Bin('username',{required: true})publicname!: string
@Bin()publicemail?: string
@Bin('age',{default: 18})publicage?: number}classUserRepositoryextendsBaseRepository<User>{protectedinstantiate(bins: AerospikeBins): User{returnUser.fromRecord(bins)}}constclient=newAerospikeClient({hosts: '127.0.0.1:3000'})asyncfunctionmain(){awaitclient.connect()constrepo=newUserRepository(client,'test','users')// Create or get userconstuser=awaitrepo.getOrCreate('user1',{name: 'Cool Name'})// Updateawaitrepo.update(user.id,{age: 25,email: 'user@email.com'})// Fetchconstfetched=awaitrepo.get('user1')// Create user entity and saveconstextraUser=newUser('user2')extraUser.name='Coolest'awaitrepo.save(extraUser)// Get all usersconstallUsers=awaitrepo.getAll()// Get users with stream filter (expression)constcoolestNameUsers=awaitrepo.getAll({stream: {filterExpression: exp.eq(exp.binStr('username'),exp.str('Coolest'))}})// Deleteawaitrepo.deleteMany(['user1',extraUser.id])}main().catch(console.error).finally(()=>client.close())
Methods
BaseEntity
Property
Type
Description
id
string | number
A unique identifier for the entity (used as Aerospike record key). Required in all entities
Method
Description
toRecord(): AerospikeBins
Serializes the entity to an Aerospike record (bins)