Skip to main content
Version: 3.0 Beta

API Reference

@zenstackhq/orm​

ClientContract<Schema>​

The interface for the ZenStack ORM client, implemented by ZenStackClient.

ZenStackClient<Schema>​

The class that implements the ORM client.

/**
* ZenStack ORM client.
*/
export const ZenStackClient = function <Schema extends SchemaDef>(
this: any,
schema: Schema,
options: ClientOptions<Schema>,
);

Options​

/**
* ZenStack client options.
*/
export type ClientOptions<Schema extends SchemaDef> = {
/**
* Kysely dialect.
*/
dialect: Dialect;

/**
* Plugins.
*/
plugins?: RuntimePlugin<Schema>[];

/**
* Logging configuration.
*/
log?: KyselyConfig['log'];

/**
* Whether to automatically fix timezone for `DateTime` fields returned by
* node-pg. Defaults to `true`.
*
* Node-pg has a terrible quirk that it interprets the date value as local
* timezone (as a `Date` object) although for `DateTime` field the data in
* DB is stored in UTC.
* @see https://github.com/brianc/node-postgres/issues/429
*/
fixPostgresTimezone?: boolean;

/**
* Whether to enable input validations expressed with attributes like `@email`,
* `@regex`, `@@validate`, etc. Defaults to `true`.
*/
validateInput?: boolean;

/**
* Options for omitting fields in ORM query results.
*/
omit?: OmitOptions<Schema>;

/**
* Computed field definitions.
*/
computedFields?: ComputedFieldsOptions<Schema>;
};

Properties​

$schema​
/**
* The schema definition.
*/
readonly $schema: Schema;
$options​
/**
* The client options.
*/
readonly $options: Options;
$auth​
/**
* The current user identity.
*/
get $auth(): AuthType<Schema> | undefined;
$qb​

Read more in the Query Builder API documentation.

/**
* The underlying Kysely query builder instance.
*/
readonly $qb: ToKysely<Schema>;
$qbRaw​

Read more in the Query Builder API documentation.

/**
* The underlying raw Kysely query builder without any ZenStack enhancements.
*/
readonly $qbRaw: AnyKysely;

APIs​

Please refer to the ORM Query API documentation for more details about CRUD APIs like findMany, create, update, etc.

$connect()​
/**
* Eagerly connects to the database.
*/
$connect(): Promise<void>;
$disconnect()​
/**
* Explicitly disconnects from the database.
*/
$disconnect(): Promise<void>;
$setAuth()​
/**
* Sets the current user identity.
*/
$setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema>;
$setOptions​
/**
* Returns a new client with new options applied.
* @example
* ```
* const dbNoValidation = db.$setOptions({ ...db.$options, validateInput: false });
* ```
*/
$setOptions<Options extends ClientOptions<Schema>>(options: Options): ClientContract<Schema, Options>;
$use()​

Read more in the Plugins documentation.

/**
* Returns a new client with the specified plugin installed.
*/
$use(plugin: RuntimePlugin<Schema>): ClientContract<Schema>;
$unuse()​

Read more in the Plugins documentation.

/**
* Returns a new client with the specified plugin removed.
*/
$unuse(pluginId: string): ClientContract<Schema>;
$unuseAll()​

Read more in the Plugins documentation.

/**
* Returns a new client with all plugins removed.
*/
$unuseAll(): ClientContract<Schema>;
Comments
Feel free to ask questions, give feedback, or report issues.

Don't Spam


You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below