Class: DORMClient
Defined in: src/client/client.ts:30
The entry point. Construct with a connection URI (and optional database name), declare models synchronously with .model(), then await connect() once at application start.
const dorm = new DORMClient(process.env.MONGODB_URL!);
const User = dorm.model("users", { ... }, { timestamps: true });
await dorm.connect();Constructors
Constructor
new DORMClient(
connectionUrl,databaseName?,options?):DORMClient
Defined in: src/client/client.ts:41
Parameters
connectionUrl
string
databaseName?
string
options?
DORMClientOptions = {}
Returns
DORMClient
Properties
connectionString
readonlyconnectionString:string
Defined in: src/client/client.ts:31
databaseName
databaseName:
string|undefined
Defined in: src/client/client.ts:32
allowRawOperators
readonlyallowRawOperators:boolean
Defined in: src/client/client.ts:34
Whether raw operator objects are permitted in filter values (see DORMClientOptions).
Accessors
__meta__
Get Signature
get __meta__():
Record<string,unknown>
Defined in: src/client/client.ts:55
Returns
Record<string, unknown>
Methods
connect()
connect():
Promise<void>
Defined in: src/client/client.ts:68
Connects to MongoDB. Idempotent — a second call is a no-op. The full URI is passed to the driver; the database name is resolved from (in order) the constructor argument, the URI path, or "test" with a warning.
Returns
Promise<void>
close()
close():
Promise<void>
Defined in: src/client/client.ts:78
Closes the underlying connection.
Returns
Promise<void>
isConnected()
isConnected():
boolean
Defined in: src/client/client.ts:85
Returns
boolean
model()
model<
S,O>(name,schema,options?):Model<S,O>
Defined in: src/client/client.ts:93
Declares a model. Synchronous and safe to call before connect(). Calling again with the same name returns the already-registered model.
Type Parameters
S
S extends SchemaDef
O
O extends ModelOptions = ModelOptions
Parameters
name
string
schema
S
options?
O
Returns
Model<S, O>
ensureIndexes()
ensureIndexes():
Promise<void>
Defined in: src/client/client.ts:108
Creates the unique/index indexes declared across all registered models.
Returns
Promise<void>
transaction()
transaction<
T>(fn):Promise<T>
Defined in: src/client/client.ts:119
Runs fn inside a MongoDB transaction, committing on success and aborting on error. Pass the session to writes via .session(session) / create(data, { session }). Requires a replica-set deployment.
Type Parameters
T
T
Parameters
fn
(session) => Promise<T>
Returns
Promise<T>