Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@mikro-orm/sql

Package Overview
Dependencies
Maintainers
1
Versions
186
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.0-dev.207
to
7.0.0-dev.208
+1
-1
dialects/mysql/MySqlSchemaHelper.d.ts

@@ -19,3 +19,3 @@ import { type Dictionary, type Type } from '@mikro-orm/core';

getListTablesSQL(): string;
getListViewsSQL(schemaName?: string): string;
getListViewsSQL(): string;
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection, schemaName?: string): Promise<void>;

@@ -22,0 +22,0 @@ loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;

@@ -36,7 +36,7 @@ import { EnumType, StringType, TextType } from '@mikro-orm/core';

}
getListViewsSQL(schemaName) {
getListViewsSQL() {
return `select table_name as view_name, nullif(table_schema, schema()) as schema_name, view_definition from information_schema.views where table_schema = schema()`;
}
async loadViews(schema, connection, schemaName) {
const views = await connection.execute(this.getListViewsSQL(schemaName));
const views = await connection.execute(this.getListViewsSQL());
for (const view of views) {

@@ -43,0 +43,0 @@ // MySQL information_schema.views.view_definition requires SHOW VIEW privilege

@@ -20,2 +20,3 @@ import { type Dictionary } from '@mikro-orm/core';

getListTablesSQL(): string;
private getIgnoredViewsCondition;
getListViewsSQL(): string;

@@ -22,0 +23,0 @@ loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection): Promise<void>;

@@ -1,3 +0,5 @@

import { EnumType, Type, Utils, DeferMode } from '@mikro-orm/core';
import { DeferMode, EnumType, Type, Utils } from '@mikro-orm/core';
import { SchemaHelper } from '../../schema/SchemaHelper.js';
/** PostGIS system views that should be automatically ignored */
const POSTGIS_VIEWS = ['geography_columns', 'geometry_columns'];
export class PostgreSqlSchemaHelper extends SchemaHelper {

@@ -32,2 +34,5 @@ static DEFAULT_VALUES = {

}
getIgnoredViewsCondition() {
return POSTGIS_VIEWS.map(v => `table_name != '${v}'`).join(' and ');
}
getListViewsSQL() {

@@ -37,2 +42,3 @@ return `select table_name as view_name, table_schema as schema_name, view_definition `

+ `where ${this.getIgnoredNamespacesConditionSQL('table_schema')} `
+ `and ${this.getIgnoredViewsCondition()} `
+ `order by table_name`;

@@ -39,0 +45,0 @@ }

@@ -16,2 +16,3 @@ import { type Connection } from '@mikro-orm/core';

getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
private getIgnoredViewsCondition;
getListViewsSQL(): string;

@@ -18,0 +19,0 @@ loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection, schemaName?: string): Promise<void>;

import { Utils } from '@mikro-orm/core';
import { SchemaHelper } from '../../schema/SchemaHelper.js';
/** SpatiaLite system views that should be automatically ignored */
const SPATIALITE_VIEWS = [
'geometry_columns',
'spatial_ref_sys',
'views_geometry_columns',
'virts_geometry_columns',
'geom_cols_ref_sys',
'spatial_ref_sys_aux',
'vector_layers',
'vector_layers_auth',
'vector_layers_field_infos',
'vector_layers_statistics',
'ElementaryGeometries',
];
export class SqliteSchemaHelper extends SchemaHelper {

@@ -46,4 +60,7 @@ disableForeignKeysSQL() {

}
getIgnoredViewsCondition() {
return SPATIALITE_VIEWS.map(v => `name != '${v}'`).join(' and ');
}
getListViewsSQL() {
return `select name as view_name, sql as view_definition from sqlite_master where type = 'view' order by name`;
return `select name as view_name, sql as view_definition from sqlite_master where type = 'view' and ${this.getIgnoredViewsCondition()} order by name`;
}

@@ -66,3 +83,3 @@ async loadViews(schema, connection, schemaName) {

const prefix = this.getSchemaPrefix(dbName);
const views = await connection.execute(`select name as view_name, sql as view_definition from ${prefix}sqlite_master where type = 'view' order by name`);
const views = await connection.execute(`select name as view_name, sql as view_definition from ${prefix}sqlite_master where type = 'view' and ${this.getIgnoredViewsCondition()} order by name`);
for (const view of views) {

@@ -69,0 +86,0 @@ schema.addView(view.view_name, dbName, this.extractViewDefinition(view.view_definition));

{
"name": "@mikro-orm/sql",
"version": "7.0.0-dev.207",
"version": "7.0.0-dev.208",
"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.",

@@ -59,4 +59,4 @@ "type": "module",

"peerDependencies": {
"@mikro-orm/core": "7.0.0-dev.207"
"@mikro-orm/core": "7.0.0-dev.208"
}
}

@@ -43,3 +43,3 @@ import { type Configuration, type Dictionary, type EntityMetadata } from '@mikro-orm/core';

getNamespaces(): string[];
static create(connection: AbstractSqlConnection, platform: AbstractSqlPlatform, config: Configuration, schemaName?: string, schemas?: string[], takeTables?: (string | RegExp)[], skipTables?: (string | RegExp)[]): Promise<DatabaseSchema>;
static create(connection: AbstractSqlConnection, platform: AbstractSqlPlatform, config: Configuration, schemaName?: string, schemas?: string[], takeTables?: (string | RegExp)[], skipTables?: (string | RegExp)[], skipViews?: (string | RegExp)[]): Promise<DatabaseSchema>;
static fromMetadata(metadata: EntityMetadata[], platform: AbstractSqlPlatform, config: Configuration, schemaName?: string, em?: any): DatabaseSchema;

@@ -49,2 +49,3 @@ private static getViewDefinition;

private static matchName;
private static isNameAllowed;
private static isTableNameAllowed;

@@ -51,0 +52,0 @@ private static shouldHaveColumn;

@@ -78,3 +78,3 @@ import { ReferenceKind, isRaw, } from '@mikro-orm/core';

}
static async create(connection, platform, config, schemaName, schemas, takeTables, skipTables) {
static async create(connection, platform, config, schemaName, schemas, takeTables, skipTables, skipViews) {
const schema = new DatabaseSchema(platform, schemaName ?? config.get('schema') ?? platform.getDefaultSchemaName());

@@ -93,2 +93,6 @@ const allTables = await platform.getSchemaHelper().getAllTables(connection, schemas);

}
// Filter out skipped views
if (skipViews && skipViews.length > 0) {
schema.views = schema.views.filter(v => this.isNameAllowed(v.name, skipViews));
}
return schema;

@@ -198,5 +202,8 @@ }

}
static isNameAllowed(name, skipNames) {
return !(skipNames?.some(pattern => this.matchName(name, pattern)) ?? false);
}
static isTableNameAllowed(tableName, takeTables, skipTables) {
return ((takeTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? true) &&
!(skipTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? false));
this.isNameAllowed(tableName, skipTables));
}

@@ -203,0 +210,0 @@ static shouldHaveColumn(meta, prop, skipColumns) {

@@ -27,3 +27,3 @@ import { type Connection, type Dictionary, RawQueryFragment } from '@mikro-orm/core';

getListViewsSQL(): string;
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection): Promise<void>;
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection, schemaName?: string): Promise<void>;
getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column, schemaName?: string): string;

@@ -71,2 +71,3 @@ getCreateIndexSQL(tableName: string, index: IndexDef): string;

skipTables?: (string | RegExp)[];
skipViews?: (string | RegExp)[];
skipColumns?: Dictionary<(string | RegExp)[]>;

@@ -73,0 +74,0 @@ managementDbName?: string;

@@ -74,3 +74,3 @@ import { RawQueryFragment, Utils } from '@mikro-orm/core';

}
async loadViews(schema, connection) {
async loadViews(schema, connection, schemaName) {
throw new Error('Not supported by given driver');

@@ -77,0 +77,0 @@ }

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

skipTables?: (string | RegExp)[];
skipViews?: (string | RegExp)[];
skipColumns?: Dictionary<(string | RegExp)[]>;

@@ -14,0 +15,0 @@ managementDbName?: string;

@@ -142,3 +142,3 @@ import { AbstractSchemaGenerator, CommitOrderCalculator, Utils, } from '@mikro-orm/core';

const schemas = this.getTargetSchema(options.schema).getNamespaces();
const schema = await DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas);
const schema = await DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas, undefined, this.options.skipTables, this.options.skipViews);
const ret = [];

@@ -223,3 +223,3 @@ // Drop views first (views may depend on tables)

const schemas = toSchema.getNamespaces();
const fromSchema = options.fromSchema ?? (await DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas, undefined, this.options.skipTables));
const fromSchema = options.fromSchema ?? (await DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas, undefined, this.options.skipTables, this.options.skipViews));
const wildcardSchemaTables = [...this.metadata.getAll().values()].filter(meta => meta.schema === '*').map(meta => meta.tableName);

@@ -226,0 +226,0 @@ fromSchema.prune(options.schema, wildcardSchemaTables);

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