hysteria-orm 11.0.4 → 11.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.cts CHANGED
@@ -695,7 +695,7 @@ interface SqliteDataSourceInput extends CommonDataSourceInput {
695
695
  * @description The filename of the database file for SQLite
696
696
  * @default ":memory:"
697
697
  */
698
- readonly database?: ":memory:" | (string & {});
698
+ readonly database?: ":memory:" | "file::memory:?cache=shared" | (string & {});
699
699
  }
700
700
  interface NotNullableSqliteDataSourceInput extends SqliteDataSourceInput {
701
701
  readonly type?: "sqlite";
@@ -735,6 +735,26 @@ type ConnectionPolicies = {
735
735
  * and programmatic models created via `defineModel`.
736
736
  */
737
737
  type SqlDataSourceModel = AnyModelConstructor;
738
+ /**
739
+ * @description Migration lock configuration
740
+ */
741
+ type MigrationLockConfig = {
742
+ /**
743
+ * @description Enable/disable migration locking
744
+ * @default true
745
+ */
746
+ enabled?: boolean;
747
+ /**
748
+ * @description Lock timeout in milliseconds for migration advisory lock acquisition
749
+ * @default 30000
750
+ */
751
+ timeout?: number;
752
+ /**
753
+ * @description Custom lock key value - can be string, number, or function returning string|number
754
+ * @default "hysteria_migration_lock"
755
+ */
756
+ customValue?: string | number | (() => string | number);
757
+ };
738
758
  /**
739
759
  * @description Base migration configuration options available for all databases
740
760
  */
@@ -750,12 +770,13 @@ type MigrationConfigBase = {
750
770
  */
751
771
  tsconfig?: string;
752
772
  /**
753
- * @description Acquire advisory lock before running migrations to prevent concurrent execution, can be overridden in the cli command
773
+ * @description Migration lock configuration - can be boolean to enable/disable, or an object for advanced options
754
774
  * @default true
755
775
  */
756
- lock?: boolean;
776
+ lock?: boolean | MigrationLockConfig;
757
777
  /**
758
- * @description Lock timeout in milliseconds for migration advisory lock acquisition, can be overridden in the cli command
778
+ * @deprecated Use lock.timeout instead. Kept for backward compatibility.
779
+ * @description Lock timeout in milliseconds for migration advisory lock acquisition
759
780
  * @default 30000
760
781
  */
761
782
  lockTimeout?: number;
@@ -801,6 +822,13 @@ type SqlDataSourceInputBase<T extends Record<string, SqlDataSourceModel> = {}, C
801
822
  * @default false
802
823
  */
803
824
  readonly logs?: boolean | LoggerConfig;
825
+ /**
826
+ * @description Enable AsyncLocalStorage (CLS) for automatic transaction propagation.
827
+ * When enabled, queries inside `sql.transaction(callback)` automatically use the active
828
+ * transaction without explicit passing.
829
+ * @default true
830
+ */
831
+ readonly clsEnabled?: boolean;
804
832
  /**
805
833
  * @description The connection policies to use for the sql data source that are not configured in the driverOptions
806
834
  */
@@ -1803,6 +1831,93 @@ declare class SchemaBuilder implements PromiseLike<void> {
1803
1831
  * @description Returns true if the builder execution failed
1804
1832
  */
1805
1833
  hasFailed(): boolean;
1834
+ /**
1835
+ * @description Checks if a table exists in the database
1836
+ * @param tableName - The name of the table to check
1837
+ * @returns Promise<boolean> - true if table exists, false otherwise
1838
+ */
1839
+ hasTable(tableName: string): Promise<boolean>;
1840
+ /**
1841
+ * @description Checks if a column exists in a table
1842
+ * @param tableName - The name of the table
1843
+ * @param columnName - The name of the column to check
1844
+ * @returns Promise<boolean> - true if column exists in table, false otherwise
1845
+ */
1846
+ hasColumn(tableName: string, columnName: string): Promise<boolean>;
1847
+ /**
1848
+ * @description Checks if multiple columns exist in a table
1849
+ * @param tableName - The name of the table
1850
+ * @param columnNames - Array of column names to check
1851
+ * @returns Promise<boolean> - true if all columns exist in table, false otherwise
1852
+ */
1853
+ hasColumns(tableName: string, ...columnNames: string[]): Promise<boolean>;
1854
+ /**
1855
+ * @description Checks if an index exists on a table
1856
+ * @param tableName - The name of the table
1857
+ * @param indexName - The name of the index to check
1858
+ * @returns Promise<boolean> - true if index exists on table, false otherwise
1859
+ */
1860
+ hasIndex(tableName: string, indexName: string): Promise<boolean>;
1861
+ /**
1862
+ * @description Checks if a table has a primary key
1863
+ * @param tableName - The name of the table
1864
+ * @returns Promise<boolean> - true if table has primary key, false otherwise
1865
+ */
1866
+ hasPrimaryKey(tableName: string): Promise<boolean>;
1867
+ /**
1868
+ * @description Checks if a unique constraint exists on a table for given columns
1869
+ * @param tableName - The name of the table
1870
+ * @param columns - Array of column names (or single string) that form the unique constraint
1871
+ * @returns Promise<boolean> - true if unique constraint exists, false otherwise
1872
+ */
1873
+ hasUnique(tableName: string, columns: string[] | string): Promise<boolean>;
1874
+ /**
1875
+ * @description Checks if a foreign key constraint exists on a table for given columns
1876
+ * @param tableName - The name of the table
1877
+ * @param columns - Array of column names that form the foreign key
1878
+ * @returns Promise<boolean> - true if foreign key exists, false otherwise
1879
+ */
1880
+ hasForeignKey(tableName: string, columns: string[]): Promise<boolean>;
1881
+ /**
1882
+ * @description Checks if a check constraint exists on a table
1883
+ * @param tableName - The name of the table
1884
+ * @param constraintName - The name of the check constraint to check
1885
+ * @returns Promise<boolean> - true if check constraint exists, false otherwise
1886
+ */
1887
+ hasCheckConstraint(tableName: string, constraintName: string): Promise<boolean>;
1888
+ /**
1889
+ * @description Gets all table names in the database
1890
+ * @returns Promise<string[]> - Array of table names
1891
+ */
1892
+ getTables(): Promise<string[]>;
1893
+ /**
1894
+ * @description Gets all column names for a table
1895
+ * @param tableName - The name of the table
1896
+ * @returns Promise<string[]> - Array of column names
1897
+ */
1898
+ getColumnListing(tableName: string): Promise<string[]>;
1899
+ /**
1900
+ * @description Drops a table if it exists
1901
+ * @param table - The name of the table to drop
1902
+ * @returns this for chaining
1903
+ */
1904
+ dropTableIfExists(table: string): this;
1905
+ /**
1906
+ * @description Drops an index if it exists
1907
+ * @param indexName - The name of the index
1908
+ * @param table - Table name (required for existence check)
1909
+ * @returns Promise<void> - executes immediately, not chainable
1910
+ * @mysql requires table name for existence check
1911
+ */
1912
+ dropIndexIfExists(indexName: string, table: string): Promise<void>;
1913
+ /**
1914
+ * @description Renames a column in a table
1915
+ * @param tableName - The name of the table
1916
+ * @param oldName - The current column name
1917
+ * @param newName - The new column name
1918
+ * @returns this for chaining
1919
+ */
1920
+ renameColumn(tableName: string, oldName: string, newName: string): this;
1806
1921
  }
1807
1922
 
1808
1923
  interface IntrospectedColumn {
@@ -4791,6 +4906,15 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4791
4906
  * @description Options provided in the sql data source initialization
4792
4907
  */
4793
4908
  inputDetails: SqlDataSourceInput<D, T, C>;
4909
+ /**
4910
+ * @description Unique identifier shared across all clones of the same logical data source.
4911
+ * Used to verify ALS transactions belong to this instance.
4912
+ */
4913
+ id: string;
4914
+ /**
4915
+ * @description Whether AsyncLocalStorage (CLS) transaction auto-propagation is enabled.
4916
+ */
4917
+ private readonly clsEnabled;
4794
4918
  /**
4795
4919
  * @description Adapter for `useCache`, uses an in memory strategy by default
4796
4920
  */
@@ -4805,7 +4929,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4805
4929
  migrationConfig: {
4806
4930
  path: string;
4807
4931
  tsconfig?: string;
4808
- lock: boolean;
4932
+ lock: boolean | MigrationLockConfig;
4809
4933
  transactional: boolean;
4810
4934
  lockTimeout?: number;
4811
4935
  };
@@ -4925,6 +5049,11 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4925
5049
  * @returns A slave SqlDataSource instance or null if no slaves are available
4926
5050
  */
4927
5051
  getSlave(): SqlDataSource<D, T, C> | null;
5052
+ /**
5053
+ * @description Returns the SqlDataSource that should execute the next query,
5054
+ * respecting (in order): explicit global transaction, ALS transaction, then self.
5055
+ */
5056
+ getTransactionBoundSqlDataSource(): SqlDataSource | null;
4928
5057
  /**
4929
5058
  * @description Uses the cache adapter to get a value from the cache
4930
5059
  * @param key The key to get the value from
@@ -5027,6 +5156,9 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
5027
5156
  * @param cb if a callback is provided, it will execute the callback and commit or rollback the transaction based on the callback's success or failure
5028
5157
  * @param options.isolationLevel The isolation level to use for the transaction
5029
5158
  * @sqlite ignores the isolation level
5159
+ * @warning SQLite `:memory:` databases use `file::memory:?cache=shared`
5160
+ * to allow transaction connections to share the same in-memory database.
5161
+ * Without shared cache each connection would see an empty fresh database.
5030
5162
  */
5031
5163
  transaction(options?: StartTransactionOptions): Promise<Transaction>;
5032
5164
  transaction<T>(cb: (trx: Transaction) => Promise<T>, options?: StartTransactionOptions): Promise<T>;
@@ -5135,6 +5267,71 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
5135
5267
  * @description Introspects table columns metadata
5136
5268
  */
5137
5269
  getTableInfo(table: string): Promise<TableColumnInfo[]>;
5270
+ /**
5271
+ * @description Checks if a table exists in the database
5272
+ * @param tableName - The name of the table to check
5273
+ * @returns Promise<boolean> - true if table exists, false otherwise
5274
+ */
5275
+ hasTable(tableName: string): Promise<boolean>;
5276
+ /**
5277
+ * @description Checks if a column exists in a table
5278
+ * @param tableName - The name of the table
5279
+ * @param columnName - The name of the column to check
5280
+ * @returns Promise<boolean> - true if column exists in table, false otherwise
5281
+ */
5282
+ hasColumn(tableName: string, columnName: string): Promise<boolean>;
5283
+ /**
5284
+ * @description Checks if multiple columns exist in a table
5285
+ * @param tableName - The name of the table
5286
+ * @param columnNames - Array of column names to check
5287
+ * @returns Promise<boolean> - true if all columns exist in table, false otherwise
5288
+ */
5289
+ hasColumns(tableName: string, ...columnNames: string[]): Promise<boolean>;
5290
+ /**
5291
+ * @description Checks if an index exists on a table
5292
+ * @param tableName - The name of the table
5293
+ * @param indexName - The name of the index to check
5294
+ * @returns Promise<boolean> - true if index exists on table, false otherwise
5295
+ */
5296
+ hasIndex(tableName: string, indexName: string): Promise<boolean>;
5297
+ /**
5298
+ * @description Checks if a table has a primary key
5299
+ * @param tableName - The name of the table
5300
+ * @returns Promise<boolean> - true if table has primary key, false otherwise
5301
+ */
5302
+ hasPrimaryKey(tableName: string): Promise<boolean>;
5303
+ /**
5304
+ * @description Checks if a unique constraint exists on a table for given columns
5305
+ * @param tableName - The name of the table
5306
+ * @param columns - Array of column names (or single string) that form the unique constraint
5307
+ * @returns Promise<boolean> - true if unique constraint exists, false otherwise
5308
+ */
5309
+ hasUnique(tableName: string, columns: string[] | string): Promise<boolean>;
5310
+ /**
5311
+ * @description Checks if a foreign key constraint exists on a table for given columns
5312
+ * @param tableName - The name of the table
5313
+ * @param columns - Array of column names that form the foreign key
5314
+ * @returns Promise<boolean> - true if foreign key exists, false otherwise
5315
+ */
5316
+ hasForeignKey(tableName: string, columns: string[]): Promise<boolean>;
5317
+ /**
5318
+ * @description Checks if a check constraint exists on a table
5319
+ * @param tableName - The name of the table
5320
+ * @param constraintName - The name of the check constraint to check
5321
+ * @returns Promise<boolean> - true if check constraint exists, false otherwise
5322
+ */
5323
+ hasCheckConstraint(tableName: string, constraintName: string): Promise<boolean>;
5324
+ /**
5325
+ * @description Gets all table names in the database
5326
+ * @returns Promise<string[]> - Array of table names
5327
+ */
5328
+ getTables(): Promise<string[]>;
5329
+ /**
5330
+ * @description Gets all column names for a table
5331
+ * @param tableName - The name of the table
5332
+ * @returns Promise<string[]> - Array of column names
5333
+ */
5334
+ getColumnListing(tableName: string): Promise<string[]>;
5138
5335
  /**
5139
5336
  * @description Introspects table indexes metadata
5140
5337
  */
@@ -8143,4 +8340,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
8143
8340
  $id?: string;
8144
8341
  }>;
8145
8342
 
8146
- export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyModelConstructor, type BaseModelMethodOptions, BaseSeeder, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, ClientMigrator, type ColCharOptions, type ColJsonbOptions, type ColMediumIntOptions, type ColSmallIntOptions, type ColTinyIntOptions, type ColVarbinaryOptions, Collection, type CollectionDefinition, type ColumnDef, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type CreateSchemaResult, type CustomLogger, type DataSourceInput, type DataSourceType, type DateAutoHook, type DefinedCollection, type DefinedModel, type DefinedView, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type FindReturnType, type GetColumnType, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type InferPK, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, type JsonPathInput, type JsonPaths, type LoadOptions, type LoggerConfig, type ManyOptions, Migration, type MigrationConfig, type MigrationConfigBase, type ModelColumns, type ModelDataProperties, type ModelInstanceType, type ModelKey, ModelQueryBuilder, type ModelQueryResult, type ModelRelation, type ModelSelectTuple, type ModelSelectableInput, type ModelWithoutRelations, type ModelsProxy, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MutationReturningResult, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NullableColumn, type NumberModelKey, ObserverChain, ObserverChainWrapper, type OneOptions, type Operation, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PingResult, type PostgresSqlDataSourceInput, type PrimaryColumnDef, type PropNamespace, type PropertyDef, QueryBuilder, type QueryContext, type QueryContextWithDuration, type QueryObserver, type RawModelKey, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationDef, type RelationDefinitions, type RelationHelpers, type RelationLoadStrategy, type RelationQueryBuilderType, type ReplicationType, type ResolveColumnType, type ResolveJsonPathType, type ReturningColumns, type ReturningKey, type ReturningParam, type ReturningResult, type ReturningResultMany, type ReturningSupported, Schema, SchemaBuilder, type SchemaLookup, type SchemaRelDef, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type StripTablePrefix, type SubQueryable, type TableFormat, Transaction, type TransactionExecutionOptions, type TypedDefault, type TypedJsonPathInput, type TypedPrepare, type TypedSerialize, type UseCacheReturnType, type UseConnectionInput, type ValidationContext, ValidationError, type ValidationResult, type Validator, type ViewDefinition, WriteOperation, type WriteReturnType, col, createSchema, defineCollection, defineMigrator, defineModel, defineModelFactory, defineRelations, defineView, deriveOperationFromQuery, email, enumValidator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, type getPoolReturnType, HysteriaLogger as logger, max, maxLength, min, minLength, pattern, prop, RedisDataSource as redis, required, url };
8343
+ export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyModelConstructor, type BaseModelMethodOptions, BaseSeeder, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, ClientMigrator, type ColCharOptions, type ColJsonbOptions, type ColMediumIntOptions, type ColSmallIntOptions, type ColTinyIntOptions, type ColVarbinaryOptions, Collection, type CollectionDefinition, type ColumnDef, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type CreateSchemaResult, type CustomLogger, type DataSourceInput, type DataSourceType, type DateAutoHook, type DefinedCollection, type DefinedModel, type DefinedView, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type FindReturnType, type GetColumnType, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type InferPK, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, type JsonPathInput, type JsonPaths, type LoadOptions, type LoggerConfig, type ManyOptions, Migration, type MigrationConfig, type MigrationConfigBase, type MigrationLockConfig, type ModelColumns, type ModelDataProperties, type ModelInstanceType, type ModelKey, ModelQueryBuilder, type ModelQueryResult, type ModelRelation, type ModelSelectTuple, type ModelSelectableInput, type ModelWithoutRelations, type ModelsProxy, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MutationReturningResult, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NullableColumn, type NumberModelKey, ObserverChain, ObserverChainWrapper, type OneOptions, type Operation, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PingResult, type PostgresSqlDataSourceInput, type PrimaryColumnDef, type PropNamespace, type PropertyDef, QueryBuilder, type QueryContext, type QueryContextWithDuration, type QueryObserver, type RawModelKey, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationDef, type RelationDefinitions, type RelationHelpers, type RelationLoadStrategy, type RelationQueryBuilderType, type ReplicationType, type ResolveColumnType, type ResolveJsonPathType, type ReturningColumns, type ReturningKey, type ReturningParam, type ReturningResult, type ReturningResultMany, type ReturningSupported, Schema, SchemaBuilder, type SchemaLookup, type SchemaRelDef, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type StripTablePrefix, type SubQueryable, type TableFormat, Transaction, type TransactionExecutionOptions, type TypedDefault, type TypedJsonPathInput, type TypedPrepare, type TypedSerialize, type UseCacheReturnType, type UseConnectionInput, type ValidationContext, ValidationError, type ValidationResult, type Validator, type ViewDefinition, WriteOperation, type WriteReturnType, col, createSchema, defineCollection, defineMigrator, defineModel, defineModelFactory, defineRelations, defineView, deriveOperationFromQuery, email, enumValidator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, type getPoolReturnType, HysteriaLogger as logger, max, maxLength, min, minLength, pattern, prop, RedisDataSource as redis, required, url };
package/lib/index.d.ts CHANGED
@@ -695,7 +695,7 @@ interface SqliteDataSourceInput extends CommonDataSourceInput {
695
695
  * @description The filename of the database file for SQLite
696
696
  * @default ":memory:"
697
697
  */
698
- readonly database?: ":memory:" | (string & {});
698
+ readonly database?: ":memory:" | "file::memory:?cache=shared" | (string & {});
699
699
  }
700
700
  interface NotNullableSqliteDataSourceInput extends SqliteDataSourceInput {
701
701
  readonly type?: "sqlite";
@@ -735,6 +735,26 @@ type ConnectionPolicies = {
735
735
  * and programmatic models created via `defineModel`.
736
736
  */
737
737
  type SqlDataSourceModel = AnyModelConstructor;
738
+ /**
739
+ * @description Migration lock configuration
740
+ */
741
+ type MigrationLockConfig = {
742
+ /**
743
+ * @description Enable/disable migration locking
744
+ * @default true
745
+ */
746
+ enabled?: boolean;
747
+ /**
748
+ * @description Lock timeout in milliseconds for migration advisory lock acquisition
749
+ * @default 30000
750
+ */
751
+ timeout?: number;
752
+ /**
753
+ * @description Custom lock key value - can be string, number, or function returning string|number
754
+ * @default "hysteria_migration_lock"
755
+ */
756
+ customValue?: string | number | (() => string | number);
757
+ };
738
758
  /**
739
759
  * @description Base migration configuration options available for all databases
740
760
  */
@@ -750,12 +770,13 @@ type MigrationConfigBase = {
750
770
  */
751
771
  tsconfig?: string;
752
772
  /**
753
- * @description Acquire advisory lock before running migrations to prevent concurrent execution, can be overridden in the cli command
773
+ * @description Migration lock configuration - can be boolean to enable/disable, or an object for advanced options
754
774
  * @default true
755
775
  */
756
- lock?: boolean;
776
+ lock?: boolean | MigrationLockConfig;
757
777
  /**
758
- * @description Lock timeout in milliseconds for migration advisory lock acquisition, can be overridden in the cli command
778
+ * @deprecated Use lock.timeout instead. Kept for backward compatibility.
779
+ * @description Lock timeout in milliseconds for migration advisory lock acquisition
759
780
  * @default 30000
760
781
  */
761
782
  lockTimeout?: number;
@@ -801,6 +822,13 @@ type SqlDataSourceInputBase<T extends Record<string, SqlDataSourceModel> = {}, C
801
822
  * @default false
802
823
  */
803
824
  readonly logs?: boolean | LoggerConfig;
825
+ /**
826
+ * @description Enable AsyncLocalStorage (CLS) for automatic transaction propagation.
827
+ * When enabled, queries inside `sql.transaction(callback)` automatically use the active
828
+ * transaction without explicit passing.
829
+ * @default true
830
+ */
831
+ readonly clsEnabled?: boolean;
804
832
  /**
805
833
  * @description The connection policies to use for the sql data source that are not configured in the driverOptions
806
834
  */
@@ -1803,6 +1831,93 @@ declare class SchemaBuilder implements PromiseLike<void> {
1803
1831
  * @description Returns true if the builder execution failed
1804
1832
  */
1805
1833
  hasFailed(): boolean;
1834
+ /**
1835
+ * @description Checks if a table exists in the database
1836
+ * @param tableName - The name of the table to check
1837
+ * @returns Promise<boolean> - true if table exists, false otherwise
1838
+ */
1839
+ hasTable(tableName: string): Promise<boolean>;
1840
+ /**
1841
+ * @description Checks if a column exists in a table
1842
+ * @param tableName - The name of the table
1843
+ * @param columnName - The name of the column to check
1844
+ * @returns Promise<boolean> - true if column exists in table, false otherwise
1845
+ */
1846
+ hasColumn(tableName: string, columnName: string): Promise<boolean>;
1847
+ /**
1848
+ * @description Checks if multiple columns exist in a table
1849
+ * @param tableName - The name of the table
1850
+ * @param columnNames - Array of column names to check
1851
+ * @returns Promise<boolean> - true if all columns exist in table, false otherwise
1852
+ */
1853
+ hasColumns(tableName: string, ...columnNames: string[]): Promise<boolean>;
1854
+ /**
1855
+ * @description Checks if an index exists on a table
1856
+ * @param tableName - The name of the table
1857
+ * @param indexName - The name of the index to check
1858
+ * @returns Promise<boolean> - true if index exists on table, false otherwise
1859
+ */
1860
+ hasIndex(tableName: string, indexName: string): Promise<boolean>;
1861
+ /**
1862
+ * @description Checks if a table has a primary key
1863
+ * @param tableName - The name of the table
1864
+ * @returns Promise<boolean> - true if table has primary key, false otherwise
1865
+ */
1866
+ hasPrimaryKey(tableName: string): Promise<boolean>;
1867
+ /**
1868
+ * @description Checks if a unique constraint exists on a table for given columns
1869
+ * @param tableName - The name of the table
1870
+ * @param columns - Array of column names (or single string) that form the unique constraint
1871
+ * @returns Promise<boolean> - true if unique constraint exists, false otherwise
1872
+ */
1873
+ hasUnique(tableName: string, columns: string[] | string): Promise<boolean>;
1874
+ /**
1875
+ * @description Checks if a foreign key constraint exists on a table for given columns
1876
+ * @param tableName - The name of the table
1877
+ * @param columns - Array of column names that form the foreign key
1878
+ * @returns Promise<boolean> - true if foreign key exists, false otherwise
1879
+ */
1880
+ hasForeignKey(tableName: string, columns: string[]): Promise<boolean>;
1881
+ /**
1882
+ * @description Checks if a check constraint exists on a table
1883
+ * @param tableName - The name of the table
1884
+ * @param constraintName - The name of the check constraint to check
1885
+ * @returns Promise<boolean> - true if check constraint exists, false otherwise
1886
+ */
1887
+ hasCheckConstraint(tableName: string, constraintName: string): Promise<boolean>;
1888
+ /**
1889
+ * @description Gets all table names in the database
1890
+ * @returns Promise<string[]> - Array of table names
1891
+ */
1892
+ getTables(): Promise<string[]>;
1893
+ /**
1894
+ * @description Gets all column names for a table
1895
+ * @param tableName - The name of the table
1896
+ * @returns Promise<string[]> - Array of column names
1897
+ */
1898
+ getColumnListing(tableName: string): Promise<string[]>;
1899
+ /**
1900
+ * @description Drops a table if it exists
1901
+ * @param table - The name of the table to drop
1902
+ * @returns this for chaining
1903
+ */
1904
+ dropTableIfExists(table: string): this;
1905
+ /**
1906
+ * @description Drops an index if it exists
1907
+ * @param indexName - The name of the index
1908
+ * @param table - Table name (required for existence check)
1909
+ * @returns Promise<void> - executes immediately, not chainable
1910
+ * @mysql requires table name for existence check
1911
+ */
1912
+ dropIndexIfExists(indexName: string, table: string): Promise<void>;
1913
+ /**
1914
+ * @description Renames a column in a table
1915
+ * @param tableName - The name of the table
1916
+ * @param oldName - The current column name
1917
+ * @param newName - The new column name
1918
+ * @returns this for chaining
1919
+ */
1920
+ renameColumn(tableName: string, oldName: string, newName: string): this;
1806
1921
  }
1807
1922
 
1808
1923
  interface IntrospectedColumn {
@@ -4791,6 +4906,15 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4791
4906
  * @description Options provided in the sql data source initialization
4792
4907
  */
4793
4908
  inputDetails: SqlDataSourceInput<D, T, C>;
4909
+ /**
4910
+ * @description Unique identifier shared across all clones of the same logical data source.
4911
+ * Used to verify ALS transactions belong to this instance.
4912
+ */
4913
+ id: string;
4914
+ /**
4915
+ * @description Whether AsyncLocalStorage (CLS) transaction auto-propagation is enabled.
4916
+ */
4917
+ private readonly clsEnabled;
4794
4918
  /**
4795
4919
  * @description Adapter for `useCache`, uses an in memory strategy by default
4796
4920
  */
@@ -4805,7 +4929,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4805
4929
  migrationConfig: {
4806
4930
  path: string;
4807
4931
  tsconfig?: string;
4808
- lock: boolean;
4932
+ lock: boolean | MigrationLockConfig;
4809
4933
  transactional: boolean;
4810
4934
  lockTimeout?: number;
4811
4935
  };
@@ -4925,6 +5049,11 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4925
5049
  * @returns A slave SqlDataSource instance or null if no slaves are available
4926
5050
  */
4927
5051
  getSlave(): SqlDataSource<D, T, C> | null;
5052
+ /**
5053
+ * @description Returns the SqlDataSource that should execute the next query,
5054
+ * respecting (in order): explicit global transaction, ALS transaction, then self.
5055
+ */
5056
+ getTransactionBoundSqlDataSource(): SqlDataSource | null;
4928
5057
  /**
4929
5058
  * @description Uses the cache adapter to get a value from the cache
4930
5059
  * @param key The key to get the value from
@@ -5027,6 +5156,9 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
5027
5156
  * @param cb if a callback is provided, it will execute the callback and commit or rollback the transaction based on the callback's success or failure
5028
5157
  * @param options.isolationLevel The isolation level to use for the transaction
5029
5158
  * @sqlite ignores the isolation level
5159
+ * @warning SQLite `:memory:` databases use `file::memory:?cache=shared`
5160
+ * to allow transaction connections to share the same in-memory database.
5161
+ * Without shared cache each connection would see an empty fresh database.
5030
5162
  */
5031
5163
  transaction(options?: StartTransactionOptions): Promise<Transaction>;
5032
5164
  transaction<T>(cb: (trx: Transaction) => Promise<T>, options?: StartTransactionOptions): Promise<T>;
@@ -5135,6 +5267,71 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
5135
5267
  * @description Introspects table columns metadata
5136
5268
  */
5137
5269
  getTableInfo(table: string): Promise<TableColumnInfo[]>;
5270
+ /**
5271
+ * @description Checks if a table exists in the database
5272
+ * @param tableName - The name of the table to check
5273
+ * @returns Promise<boolean> - true if table exists, false otherwise
5274
+ */
5275
+ hasTable(tableName: string): Promise<boolean>;
5276
+ /**
5277
+ * @description Checks if a column exists in a table
5278
+ * @param tableName - The name of the table
5279
+ * @param columnName - The name of the column to check
5280
+ * @returns Promise<boolean> - true if column exists in table, false otherwise
5281
+ */
5282
+ hasColumn(tableName: string, columnName: string): Promise<boolean>;
5283
+ /**
5284
+ * @description Checks if multiple columns exist in a table
5285
+ * @param tableName - The name of the table
5286
+ * @param columnNames - Array of column names to check
5287
+ * @returns Promise<boolean> - true if all columns exist in table, false otherwise
5288
+ */
5289
+ hasColumns(tableName: string, ...columnNames: string[]): Promise<boolean>;
5290
+ /**
5291
+ * @description Checks if an index exists on a table
5292
+ * @param tableName - The name of the table
5293
+ * @param indexName - The name of the index to check
5294
+ * @returns Promise<boolean> - true if index exists on table, false otherwise
5295
+ */
5296
+ hasIndex(tableName: string, indexName: string): Promise<boolean>;
5297
+ /**
5298
+ * @description Checks if a table has a primary key
5299
+ * @param tableName - The name of the table
5300
+ * @returns Promise<boolean> - true if table has primary key, false otherwise
5301
+ */
5302
+ hasPrimaryKey(tableName: string): Promise<boolean>;
5303
+ /**
5304
+ * @description Checks if a unique constraint exists on a table for given columns
5305
+ * @param tableName - The name of the table
5306
+ * @param columns - Array of column names (or single string) that form the unique constraint
5307
+ * @returns Promise<boolean> - true if unique constraint exists, false otherwise
5308
+ */
5309
+ hasUnique(tableName: string, columns: string[] | string): Promise<boolean>;
5310
+ /**
5311
+ * @description Checks if a foreign key constraint exists on a table for given columns
5312
+ * @param tableName - The name of the table
5313
+ * @param columns - Array of column names that form the foreign key
5314
+ * @returns Promise<boolean> - true if foreign key exists, false otherwise
5315
+ */
5316
+ hasForeignKey(tableName: string, columns: string[]): Promise<boolean>;
5317
+ /**
5318
+ * @description Checks if a check constraint exists on a table
5319
+ * @param tableName - The name of the table
5320
+ * @param constraintName - The name of the check constraint to check
5321
+ * @returns Promise<boolean> - true if check constraint exists, false otherwise
5322
+ */
5323
+ hasCheckConstraint(tableName: string, constraintName: string): Promise<boolean>;
5324
+ /**
5325
+ * @description Gets all table names in the database
5326
+ * @returns Promise<string[]> - Array of table names
5327
+ */
5328
+ getTables(): Promise<string[]>;
5329
+ /**
5330
+ * @description Gets all column names for a table
5331
+ * @param tableName - The name of the table
5332
+ * @returns Promise<string[]> - Array of column names
5333
+ */
5334
+ getColumnListing(tableName: string): Promise<string[]>;
5138
5335
  /**
5139
5336
  * @description Introspects table indexes metadata
5140
5337
  */
@@ -8143,4 +8340,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
8143
8340
  $id?: string;
8144
8341
  }>;
8145
8342
 
8146
- export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyModelConstructor, type BaseModelMethodOptions, BaseSeeder, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, ClientMigrator, type ColCharOptions, type ColJsonbOptions, type ColMediumIntOptions, type ColSmallIntOptions, type ColTinyIntOptions, type ColVarbinaryOptions, Collection, type CollectionDefinition, type ColumnDef, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type CreateSchemaResult, type CustomLogger, type DataSourceInput, type DataSourceType, type DateAutoHook, type DefinedCollection, type DefinedModel, type DefinedView, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type FindReturnType, type GetColumnType, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type InferPK, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, type JsonPathInput, type JsonPaths, type LoadOptions, type LoggerConfig, type ManyOptions, Migration, type MigrationConfig, type MigrationConfigBase, type ModelColumns, type ModelDataProperties, type ModelInstanceType, type ModelKey, ModelQueryBuilder, type ModelQueryResult, type ModelRelation, type ModelSelectTuple, type ModelSelectableInput, type ModelWithoutRelations, type ModelsProxy, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MutationReturningResult, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NullableColumn, type NumberModelKey, ObserverChain, ObserverChainWrapper, type OneOptions, type Operation, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PingResult, type PostgresSqlDataSourceInput, type PrimaryColumnDef, type PropNamespace, type PropertyDef, QueryBuilder, type QueryContext, type QueryContextWithDuration, type QueryObserver, type RawModelKey, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationDef, type RelationDefinitions, type RelationHelpers, type RelationLoadStrategy, type RelationQueryBuilderType, type ReplicationType, type ResolveColumnType, type ResolveJsonPathType, type ReturningColumns, type ReturningKey, type ReturningParam, type ReturningResult, type ReturningResultMany, type ReturningSupported, Schema, SchemaBuilder, type SchemaLookup, type SchemaRelDef, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type StripTablePrefix, type SubQueryable, type TableFormat, Transaction, type TransactionExecutionOptions, type TypedDefault, type TypedJsonPathInput, type TypedPrepare, type TypedSerialize, type UseCacheReturnType, type UseConnectionInput, type ValidationContext, ValidationError, type ValidationResult, type Validator, type ViewDefinition, WriteOperation, type WriteReturnType, col, createSchema, defineCollection, defineMigrator, defineModel, defineModelFactory, defineRelations, defineView, deriveOperationFromQuery, email, enumValidator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, type getPoolReturnType, HysteriaLogger as logger, max, maxLength, min, minLength, pattern, prop, RedisDataSource as redis, required, url };
8343
+ export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyModelConstructor, type BaseModelMethodOptions, BaseSeeder, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, ClientMigrator, type ColCharOptions, type ColJsonbOptions, type ColMediumIntOptions, type ColSmallIntOptions, type ColTinyIntOptions, type ColVarbinaryOptions, Collection, type CollectionDefinition, type ColumnDef, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type CreateSchemaResult, type CustomLogger, type DataSourceInput, type DataSourceType, type DateAutoHook, type DefinedCollection, type DefinedModel, type DefinedView, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type FindReturnType, type GetColumnType, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type InferPK, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, type JsonPathInput, type JsonPaths, type LoadOptions, type LoggerConfig, type ManyOptions, Migration, type MigrationConfig, type MigrationConfigBase, type MigrationLockConfig, type ModelColumns, type ModelDataProperties, type ModelInstanceType, type ModelKey, ModelQueryBuilder, type ModelQueryResult, type ModelRelation, type ModelSelectTuple, type ModelSelectableInput, type ModelWithoutRelations, type ModelsProxy, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MutationReturningResult, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NullableColumn, type NumberModelKey, ObserverChain, ObserverChainWrapper, type OneOptions, type Operation, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PingResult, type PostgresSqlDataSourceInput, type PrimaryColumnDef, type PropNamespace, type PropertyDef, QueryBuilder, type QueryContext, type QueryContextWithDuration, type QueryObserver, type RawModelKey, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationDef, type RelationDefinitions, type RelationHelpers, type RelationLoadStrategy, type RelationQueryBuilderType, type ReplicationType, type ResolveColumnType, type ResolveJsonPathType, type ReturningColumns, type ReturningKey, type ReturningParam, type ReturningResult, type ReturningResultMany, type ReturningSupported, Schema, SchemaBuilder, type SchemaLookup, type SchemaRelDef, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type StripTablePrefix, type SubQueryable, type TableFormat, Transaction, type TransactionExecutionOptions, type TypedDefault, type TypedJsonPathInput, type TypedPrepare, type TypedSerialize, type UseCacheReturnType, type UseConnectionInput, type ValidationContext, ValidationError, type ValidationResult, type Validator, type ViewDefinition, WriteOperation, type WriteReturnType, col, createSchema, defineCollection, defineMigrator, defineModel, defineModelFactory, defineRelations, defineView, deriveOperationFromQuery, email, enumValidator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, type getPoolReturnType, HysteriaLogger as logger, max, maxLength, min, minLength, pattern, prop, RedisDataSource as redis, required, url };