Store
Overview
Module
- package:
@aerokit/sdk/db - source: db/store.ts
- last updated:
This module provides a Store class that serves as a facade for interacting with the underlying Dirigible Data Store. The Store class offers methods for performing CRUD operations, executing parameterized queries, and retrieving metadata about entities. It abstracts away the complexities of JSON serialization and deserialization when communicating with the native Java facade, allowing developers to work with plain JavaScript objects and arrays seamlessly.
Key Features
- CRUD Operations: Create, read, update, and delete entries in the data store using simple methods.
- Query Execution: Execute parameterized queries with support for both primitive and complex parameters.
- Metadata Retrieval: Access metadata about entities, such as table names and ID fields.
- JSON Handling: Automatically handles JSON serialization and deserialization of JavaScript objects when interacting with the native Java APIs.
Use Cases
- Managing application data in a structured way using the data store.
- Executing complex queries with dynamic parameters to retrieve specific subsets of data.
- Abstracting away database interactions to allow for easier maintenance and potential future changes to the underlying data storage mechanism.
Example Usage
import { Store } from "@aerokit/sdk/db";
// Save a new entry to the "users" entity
const userId = Store.save("users", { name: "Alice", email: "alice@example.com" });Classes
Store
save()
Saves a new entry to the data store.
tsstatic save(name: string, entry: any): void;
Parameter Type Description namestringThe entity/table name. entryanyThe JavaScript object to save. Returns
- Type:
void- Description: The ID of the newly created entry (string or number).
upsert()
Inserts a new entry or updates an existing one if the ID is present.
tsstatic upsert(name: string, entry: any): void;
Parameter Type Description namestringThe entity/table name. entryanyThe JavaScript object to insert/update. Returns
- Type:
void- Description:
update()
Updates an existing entry.
tsstatic update(name: string, entry: any): void;
Parameter Type Description namestringThe entity/table name. entryanyThe JavaScript object with the ID and updated data. Returns
- Type:
void- Description:
list()
Lists entries based on optional filtering, sorting, and pagination options.
tsstatic list(name: string, options: Options): void;
Parameter Type Description namestringThe entity/table name. optionsOptionsOptional Options for query execution. Returns
- Type:
void- Description: An array of JavaScript objects.
count()
Counts the number of entries based on optional filtering options.
tsstatic count(name: string, options: Options): number;
Parameter Type Description namestringThe entity/table name. optionsOptionsOptional Options for query execution. Returns
- Type:
number- Description: The count of matching entries.
get()
Retrieves a single entry by its ID.
tsstatic get(name: string, id: any): any;
Parameter Type Description namestringThe entity/table name. idanyThe ID of the entry. Returns
- Type:
any- Description: The entry object, or undefined if not found.
remove()
Deletes an entry by its ID.
tsstatic remove(name: string, id: any): void;
Parameter Type Description namestringThe entity/table name. idanyThe ID of the entry to remove. Returns
- Type:
void- Description:
find()
Finds entries matching an example object (query-by-example).
tsstatic find(name: string, example: any, limit: number, offset: number): void;
Parameter Type Description namestringThe entity/table name. exampleanyAn object containing properties to match. limitnumberMaximum number of results to return. offsetnumberNumber of results to skip. Returns
- Type:
void- Description: An array of matching JavaScript objects.
query()
Queries all entries for a given script with pagination.
tsstatic query(query: string, parameters: any, limit: number, offset: number): void;
Parameter Type Description querystringThe query script. parametersanylimitnumberMaximum number of results to return. offsetnumberNumber of results to skip. Returns
- Type:
void- Description: An array of JavaScript objects.
queryNative()
Queries all entries for a given entity name without pagination.
tsstatic queryNative(query: string, parameters: any, limit: number, offset: number): void;
Parameter Type Description querystringThe entity/table name. parametersanylimitnumberoffsetnumberReturns
- Type:
void- Description: An array of all JavaScript objects.
getEntityName()
Gets the name of the entity associated with the store name.
tsstatic getEntityName(name: string): string;
Parameter Type Description namestringReturns
- Type:
string- Description:
getTableName()
Gets the underlying database table name for the entity.
tsstatic getTableName(name: string): string;
Parameter Type Description namestringReturns
- Type:
string- Description:
getIdName()
Gets the property name used as the ID field in the entity object.
tsstatic getIdName(name: string): string;
Parameter Type Description namestringReturns
- Type:
string- Description:
getIdColumn()
Gets the underlying database column name used for the ID field.
tsstatic getIdColumn(name: string): string;
Parameter Type Description namestringReturns
- Type:
string- Description:
