You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@mikro-orm/sql

Package Overview
Dependencies
Maintainers
1
Versions
272
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mikro-orm/sql - npm Package Compare versions

Comparing version
7.0.2-dev.13
to
7.0.2-dev.14
+12
-0
AbstractSqlConnection.d.ts

@@ -5,9 +5,13 @@ import { type ControlledTransaction, type Dialect, Kysely } from 'kysely';

import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
/** Base class for SQL database connections, built on top of Kysely. */
export declare abstract class AbstractSqlConnection extends Connection {
#private;
protected platform: AbstractSqlPlatform;
/** Creates a Kysely dialect instance with driver-specific configuration. */
abstract createKyselyDialect(overrides: Dictionary): MaybePromise<Dialect>;
/** Establishes the database connection and runs the onConnect hook. */
connect(options?: {
skipOnConnect?: boolean;
}): Promise<void>;
/** Initializes the Kysely client from driver options or a user-provided Kysely instance. */
createKysely(): MaybePromise<void>;

@@ -32,4 +36,7 @@ /**

}>;
/** Returns the underlying Kysely client, creating it synchronously if needed. */
getClient<T = any>(): Kysely<T>;
/** Ensures the Kysely client is initialized, creating it asynchronously if needed. */
initClient(): Promise<void>;
/** Executes a callback within a transaction, committing on success and rolling back on error. */
transactional<T>(cb: (trx: Transaction<ControlledTransaction<any, any>>) => Promise<T>, options?: {

@@ -42,2 +49,3 @@ isolationLevel?: IsolationLevel;

}): Promise<T>;
/** Begins a new transaction or creates a savepoint if a transaction context already exists. */
begin(options?: {

@@ -50,6 +58,10 @@ isolationLevel?: IsolationLevel;

}): Promise<ControlledTransaction<any, any>>;
/** Commits the transaction or releases the savepoint. */
commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
/** Rolls back the transaction or rolls back to the savepoint. */
rollback(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
private prepareQuery;
/** Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count. */
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: readonly unknown[], method?: 'all' | 'get' | 'run', ctx?: Transaction, loggerContext?: LoggingOptions): Promise<T>;
/** Executes a SQL query and returns an async iterable that yields results row by row. */
stream<T extends EntityData<AnyEntity>>(query: string | NativeQueryBuilder | RawQueryFragment, params?: readonly unknown[], ctx?: Transaction<Kysely<any>>, loggerContext?: LoggingOptions): AsyncIterableIterator<T>;

@@ -56,0 +68,0 @@ /** @inheritDoc */

import { CompiledQuery, Kysely } from 'kysely';
import { Connection, EventType, RawQueryFragment, Utils, } from '@mikro-orm/core';
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
/** Base class for SQL database connections, built on top of Kysely. */
export class AbstractSqlConnection extends Connection {
#client;
/** Establishes the database connection and runs the onConnect hook. */
async connect(options) {

@@ -13,2 +15,3 @@ await this.initClient();

}
/** Initializes the Kysely client from driver options or a user-provided Kysely instance. */
createKysely() {

@@ -68,2 +71,3 @@ let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions');

}
/** Returns the underlying Kysely client, creating it synchronously if needed. */
getClient() {

@@ -79,2 +83,3 @@ if (!this.#client) {

}
/** Ensures the Kysely client is initialized, creating it asynchronously if needed. */
async initClient() {

@@ -85,2 +90,3 @@ if (!this.#client) {

}
/** Executes a callback within a transaction, committing on success and rolling back on error. */
async transactional(cb, options = {}) {

@@ -98,2 +104,3 @@ const trx = await this.begin(options);

}
/** Begins a new transaction or creates a savepoint if a transaction context already exists. */
async begin(options = {}) {

@@ -138,2 +145,3 @@ if (options.ctx) {

}
/** Commits the transaction or releases the savepoint. */
async commit(ctx, eventBroadcaster, loggerContext) {

@@ -154,2 +162,3 @@ if (ctx.isRolledBack) {

}
/** Rolls back the transaction or rolls back to the savepoint. */
async rollback(ctx, eventBroadcaster, loggerContext) {

@@ -179,2 +188,3 @@ await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);

}
/** Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count. */
async execute(query, params = [], method = 'all', ctx, loggerContext) {

@@ -190,2 +200,3 @@ await this.ensureConnection();

}
/** Executes a SQL query and returns an async iterable that yields results row by row. */
async *stream(query, params = [], ctx, loggerContext) {

@@ -192,0 +203,0 @@ await this.ensureConnection();

+1
-0

@@ -9,2 +9,3 @@ import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type FormulaTable, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, type Raw, RawQueryFragment, type StreamOptions, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';

import type { InternalField } from './typings.js';
/** Base class for SQL database drivers, implementing find/insert/update/delete using QueryBuilder. */
export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlConnection = AbstractSqlConnection, Platform extends AbstractSqlPlatform = AbstractSqlPlatform> extends DatabaseDriver<Connection> {

@@ -11,0 +12,0 @@ [EntityManagerType]: SqlEntityManager<this>;

@@ -6,2 +6,3 @@ import { type RawQueryFragment, type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type IsolationLevel, type MikroORM, Platform } from '@mikro-orm/core';

import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
/** Base class for SQL database platforms, providing SQL generation and quoting utilities. */
export declare abstract class AbstractSqlPlatform extends Platform {

@@ -8,0 +9,0 @@ #private;

@@ -5,2 +5,3 @@ import { isRaw, JsonProperty, Platform, raw, Utils, } from '@mikro-orm/core';

import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
/** Base class for SQL database platforms, providing SQL generation and quoting utilities. */
export class AbstractSqlPlatform extends Platform {

@@ -7,0 +8,0 @@ static #JSON_PROPERTY_NAME_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;

+2
-2
{
"name": "@mikro-orm/sql",
"version": "7.0.2-dev.13",
"version": "7.0.2-dev.14",
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",

@@ -56,3 +56,3 @@ "keywords": [

"peerDependencies": {
"@mikro-orm/core": "7.0.2-dev.13"
"@mikro-orm/core": "7.0.2-dev.14"
},

@@ -59,0 +59,0 @@ "engines": {

import { type KyselyPlugin, type PluginTransformQueryArgs, type PluginTransformResultArgs, type QueryResult, type RootOperationNode, type UnknownRow } from 'kysely';
import type { SqlEntityManager } from '../SqlEntityManager.js';
/** Configuration options for the MikroKyselyPlugin. */
export interface MikroKyselyPluginOptions {

@@ -35,2 +36,3 @@ /**

}
/** Kysely plugin that transforms queries and results to use MikroORM entity/property naming conventions. */
export declare class MikroKyselyPlugin implements KyselyPlugin {

@@ -37,0 +39,0 @@ #private;

import { SelectQueryNode as SelectQueryNodeClass, InsertQueryNode as InsertQueryNodeClass, UpdateQueryNode as UpdateQueryNodeClass, DeleteQueryNode as DeleteQueryNodeClass, } from 'kysely';
import { MikroTransformer } from './transformer.js';
/** Kysely plugin that transforms queries and results to use MikroORM entity/property naming conventions. */
export class MikroKyselyPlugin {

@@ -4,0 +5,0 @@ static #queryNodeCache = new WeakMap();

@@ -0,1 +1,2 @@

/** Type of SQL query to be generated. */
export declare enum QueryType {

@@ -12,2 +13,3 @@ TRUNCATE = "TRUNCATE",

export declare const EMBEDDABLE_ARRAY_OPS: string[];
/** Type of SQL JOIN clause. */
export declare enum JoinType {

@@ -14,0 +16,0 @@ leftJoin = "left join",

@@ -0,1 +1,2 @@

/** Type of SQL query to be generated. */
export var QueryType;

@@ -13,2 +14,3 @@ (function (QueryType) {

export const EMBEDDABLE_ARRAY_OPS = ['$contains', '$contained', '$overlap'];
/** Type of SQL JOIN clause. */
export var JoinType;

@@ -15,0 +17,0 @@ (function (JoinType) {

import { type Dictionary, LockMode, type QueryFlag, RawQueryFragment, type Subquery } from '@mikro-orm/core';
import { QueryType } from './enums.js';
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform.js';
/** Options for Common Table Expression (CTE) definitions. */
export interface CteOptions {
/** Column names for the CTE. */
columns?: string[];

@@ -48,2 +50,3 @@ /** PostgreSQL: MATERIALIZED / NOT MATERIALIZED */

}
/** Options for specifying the target table in FROM/INTO clauses. */
export interface TableOptions {

@@ -50,0 +53,0 @@ schema?: string;

@@ -7,8 +7,13 @@ import { type Connection, type Dictionary, type Options, RawQueryFragment } from '@mikro-orm/core';

import type { DatabaseTable } from './DatabaseTable.js';
/** Base class for database-specific schema helpers. Provides SQL generation for DDL operations. */
export declare abstract class SchemaHelper {
protected readonly platform: AbstractSqlPlatform;
constructor(platform: AbstractSqlPlatform);
/** Returns SQL to prepend to schema migration scripts (e.g., disabling FK checks). */
getSchemaBeginning(_charset: string, disableForeignKeys?: boolean): string;
/** Returns SQL to disable foreign key checks. */
disableForeignKeysSQL(): string;
/** Returns SQL to re-enable foreign key checks. */
enableForeignKeysSQL(): string;
/** Returns SQL to append to schema migration scripts (e.g., re-enabling FK checks). */
getSchemaEnd(disableForeignKeys?: boolean): string;

@@ -24,8 +29,13 @@ finalizeTable(table: DatabaseTable, charset: string, collate?: string): string;

getAlterNativeEnumSQL(name: string, schema?: string, value?: string, items?: string[], oldItems?: string[]): string;
/** Loads table metadata (columns, indexes, foreign keys) from the database information schema. */
abstract loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
/** Returns the SQL query to list all tables in the database. */
getListTablesSQL(): string;
/** Retrieves all tables from the database. */
getAllTables(connection: AbstractSqlConnection, schemas?: string[]): Promise<Table[]>;
getListViewsSQL(): string;
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection, schemaName?: string): Promise<void>;
/** Returns SQL to rename a column in a table. */
getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column, schemaName?: string): string;
/** Returns SQL to create an index on a table. */
getCreateIndexSQL(tableName: string, index: IndexDef): string;

@@ -41,5 +51,8 @@ /**

protected getIndexColumns(index: IndexDef): string;
/** Returns SQL to drop an index. */
getDropIndexSQL(tableName: string, index: IndexDef): string;
getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string[];
/** Returns SQL statements to apply a table difference (add/drop/alter columns, indexes, foreign keys). */
alterTable(diff: TableDifference, safe?: boolean): string[];
/** Returns SQL to add columns to an existing table. */
getAddColumnsSQL(table: DatabaseTable, columns: Column[]): string[];

@@ -68,4 +81,6 @@ getDropColumnsSQL(tableName: string, columns: Column[], schemaName?: string): string;

append(array: string[], sql: string | string[], pad?: boolean): void;
/** Returns SQL statements to create a table with all its columns, primary key, indexes, and checks. */
createTable(table: DatabaseTable, alter?: boolean): string[];
alterTableComment(table: DatabaseTable, comment?: string): string;
/** Returns SQL to create a foreign key constraint on a table. */
createForeignKey(table: DatabaseTable, foreignKey: ForeignKey, alterTable?: boolean, inline?: boolean): string;

@@ -84,2 +99,3 @@ splitTableName(name: string, skipDefaultSchema?: boolean): [string | undefined, string];

dropConstraint(table: string, name: string): string;
/** Returns SQL to drop a table if it exists. */
dropTableIfExists(name: string, schema?: string): string;

@@ -86,0 +102,0 @@ createView(name: string, schema: string | undefined, definition: string): string;

import { RawQueryFragment, Utils } from '@mikro-orm/core';
/** Base class for database-specific schema helpers. Provides SQL generation for DDL operations. */
export class SchemaHelper {

@@ -7,2 +8,3 @@ platform;

}
/** Returns SQL to prepend to schema migration scripts (e.g., disabling FK checks). */
getSchemaBeginning(_charset, disableForeignKeys) {

@@ -14,8 +16,11 @@ if (disableForeignKeys) {

}
/** Returns SQL to disable foreign key checks. */
disableForeignKeysSQL() {
return '';
}
/** Returns SQL to re-enable foreign key checks. */
enableForeignKeysSQL() {
return '';
}
/** Returns SQL to append to schema migration scripts (e.g., re-enabling FK checks). */
getSchemaEnd(disableForeignKeys) {

@@ -67,5 +72,7 @@ if (disableForeignKeys) {

}
/** Returns the SQL query to list all tables in the database. */
getListTablesSQL() {
throw new Error('Not supported by given driver');
}
/** Retrieves all tables from the database. */
async getAllTables(connection, schemas) {

@@ -80,2 +87,3 @@ return connection.execute(this.getListTablesSQL());

}
/** Returns SQL to rename a column in a table. */
getRenameColumnSQL(tableName, oldColumnName, to, schemaName) {

@@ -89,2 +97,3 @@ tableName = this.quote(tableName);

}
/** Returns SQL to create an index on a table. */
getCreateIndexSQL(tableName, index) {

@@ -153,2 +162,3 @@ /* v8 ignore next */

}
/** Returns SQL to drop an index. */
getDropIndexSQL(tableName, index) {

@@ -163,2 +173,3 @@ return `drop index ${this.quote(index.keyName)}`;

}
/** Returns SQL statements to apply a table difference (add/drop/alter columns, indexes, foreign keys). */
alterTable(diff, safe) {

@@ -267,2 +278,3 @@ const ret = [];

}
/** Returns SQL to add columns to an existing table. */
getAddColumnsSQL(table, columns) {

@@ -483,2 +495,3 @@ const adds = columns

}
/** Returns SQL statements to create a table with all its columns, primary key, indexes, and checks. */
createTable(table, alter) {

@@ -519,2 +532,3 @@ let sql = `create table ${table.getQuotedName()} (`;

}
/** Returns SQL to create a foreign key constraint on a table. */
createForeignKey(table, foreignKey, alterTable = true, inline = false) {

@@ -630,2 +644,3 @@ if (!this.options.createForeignKeyConstraints) {

}
/** Returns SQL to drop a table if it exists. */
dropTableIfExists(name, schema) {

@@ -632,0 +647,0 @@ let sql = `drop table if exists ${this.quote(this.getTableName(name, schema))}`;

@@ -7,2 +7,3 @@ import { type ClearDatabaseOptions, type CreateSchemaOptions, type DropSchemaOptions, type EnsureDatabaseOptions, type EntityMetadata, type ISchemaGenerator, type MikroORM, type Options, type Transaction, type UpdateSchemaOptions } from '@mikro-orm/core';

import type { SchemaHelper } from './SchemaHelper.js';
/** Generates and manages SQL database schemas based on entity metadata. Supports create, update, and drop operations. */
export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<AbstractSqlDriver> implements ISchemaGenerator {

@@ -9,0 +10,0 @@ protected readonly helper: SchemaHelper;

@@ -5,2 +5,3 @@ import { CommitOrderCalculator, TableNotFoundException, Utils, } from '@mikro-orm/core';

import { SchemaComparator } from './SchemaComparator.js';
/** Generates and manages SQL database schemas based on entity metadata. Supports create, update, and drop operations. */
export class SqlSchemaGenerator extends AbstractSchemaGenerator {

@@ -7,0 +8,0 @@ helper = this.platform.getSchemaHelper();

@@ -9,3 +9,5 @@ import { type EntitySchemaWithMeta, EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type GetRepository, type QueryResult, type FilterQuery, type LoggingOptions, type RawQueryFragment } from '@mikro-orm/core';

import { type MikroKyselyPluginOptions } from './plugin/index.js';
/** Options for `SqlEntityManager.getKysely()`. */
export interface GetKyselyOptions extends MikroKyselyPluginOptions {
/** Connection type to use (`'read'` or `'write'`). */
type?: ConnectionType;

@@ -29,2 +31,3 @@ }

getKysely<TDB = undefined, TOptions extends GetKyselyOptions = GetKyselyOptions>(options?: TOptions): Kysely<TDB extends undefined ? InferKyselyDB<EntitiesFromManager<this>, TOptions> & InferClassEntityDB<AllEntitiesFromManager<this>, TOptions> : TDB>;
/** Executes a raw SQL query, using the current transaction context if available. */
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: any[], method?: 'all' | 'get' | 'run', loggerContext?: LoggingOptions): Promise<T>;

@@ -31,0 +34,0 @@ getRepository<T extends object, U extends EntityRepository<T> = SqlEntityRepository<T>>(entityName: EntityName<T>): GetRepository<T, U>;

@@ -34,2 +34,3 @@ import { EntityManager, } from '@mikro-orm/core';

}
/** Executes a raw SQL query, using the current transaction context if available. */
async execute(query, params = [], method = 'all', loggerContext) {

@@ -36,0 +37,0 @@ return this.getDriver().execute(query, params, method, this.getContext(false).getTransactionContext(), loggerContext);

import { EntityRepository, type EntityName } from '@mikro-orm/core';
import type { SqlEntityManager } from './SqlEntityManager.js';
import type { QueryBuilder } from './query/QueryBuilder.js';
/** SQL-specific entity repository with QueryBuilder support. */
export declare class SqlEntityRepository<Entity extends object> extends EntityRepository<Entity> {

@@ -5,0 +6,0 @@ protected readonly em: SqlEntityManager;

import { EntityRepository } from '@mikro-orm/core';
/** SQL-specific entity repository with QueryBuilder support. */
export class SqlEntityRepository extends EntityRepository {

@@ -3,0 +4,0 @@ em;

Sorry, the diff of this file is too big to display