Skip to main content

Class: NoSqlContext

Defined in: src/nosql/NoSqlContext.ts:13

Top-level context for NoSQL / MongoDB applications in entityTS.

Provides typed LINQ NoSqlSet<T> collections, connection lifecycle management, and scoped ACID multi-document transactions.

Constructors​

Constructor​

new NoSqlContext(adapter): NoSqlContext

Defined in: src/nosql/NoSqlContext.ts:16

Parameters​

ParameterType
adapterINoSqlAdapter

Returns​

NoSqlContext

Methods​

collection()​

collection<T>(target): NoSqlSet<T>

Defined in: src/nosql/NoSqlContext.ts:31

Returns a typed NoSqlSet<T> for the specified collection name or entity class.

Type Parameters​

Type ParameterDefault type
T extends objectany

Parameters​

ParameterTypeDescription
targetCollectionTarget<T>Collection name or Entity class constructor.

Returns​

NoSqlSet<T>

Example​

const users = ctx.collection<User>('users');
const activeAdmins = await users
.where(u => u.age >= 18 && u.role === 'admin')
.orderByDescending(u => u.createdAt)
.toList();

connect()​

connect(): Promise<void>

Defined in: src/nosql/NoSqlContext.ts:44

Connects the underlying adapter.

Returns​

Promise<void>


disconnect()​

disconnect(): Promise<void>

Defined in: src/nosql/NoSqlContext.ts:51

Disconnects the underlying adapter.

Returns​

Promise<void>


beginTransaction()​

beginTransaction(): Promise<NoSqlTransaction>

Defined in: src/nosql/NoSqlContext.ts:58

Starts a new multi-document transaction on the underlying database.

Returns​

Promise<NoSqlTransaction>


withTransaction()​

withTransaction<R>(fn): Promise<R>

Defined in: src/nosql/NoSqlContext.ts:71

Runs an operation inside an atomic multi-document transaction. Commits automatically on completion or rolls back if an error occurs.

Type Parameters​

Type Parameter
R

Parameters​

ParameterType
fn(tx) => Promise<R>

Returns​

Promise<R>


useTransaction()​

useTransaction<R>(fn): Promise<R>

Defined in: src/nosql/NoSqlContext.ts:86

Alias for withTransaction().

Type Parameters​

Type Parameter
R

Parameters​

ParameterType
fn(tx) => Promise<R>

Returns​

Promise<R>


ensureIndexes()​

ensureIndexes(indexMap?): Promise<void>

Defined in: src/nosql/NoSqlContext.ts:93

Ensures that defined indexes exist across collections.

Parameters​

ParameterType
indexMapRecord<string, object[]>

Returns​

Promise<void>

Properties​

adapter​

readonly adapter: INoSqlAdapter

Defined in: src/nosql/NoSqlContext.ts:16