Gathering detailed insights and metrics for mysql-utilities
Gathering detailed insights and metrics for mysql-utilities
Gathering detailed insights and metrics for mysql-utilities
Gathering detailed insights and metrics for mysql-utilities
@onivoro/server-typeorm-mysql
A comprehensive TypeORM MySQL integration library for NestJS applications, providing custom repositories, decorators, utilities, and enhanced MySQL-specific functionality for enterprise-scale database operations.
plethora-atlas-contrib-mysql
MySQL Utilities for the Plethora Atlas Project
@common-gear/utilities
Some utils to use Logging and MySQL
mariadb-utilities
mariaDB Utilities for node-mysql driver with specialized result types, introspection, joins and other helpful functionality.
Query builder for node-mysql with introspection, etc.
npm install mysql-utilities
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
112 Stars
95 Commits
23 Forks
9 Watchers
9 Branches
4 Contributors
Updated on Mar 29, 2025
Latest Version
1.1.4
Package Id
mysql-utilities@1.1.4
Unpacked Size
38.20 kB
Size
9.22 kB
File Count
4
NPM Version
6.14.17
Node Version
14.19.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Utilities for node-mysql driver with specialized result types, introspection and other helpful functionality for node.js. Initially this utilities were part of Impress Application Server and extracted separately for use with other frameworks.
1$ npm install mysql-utilities
Utilities can be attached to connection using mix-ins:
1// Library dependencies 2const mysql = require('mysql'); 3const mysqlUtilities = require('mysql-utilities'); 4 5const connection = mysql.createConnection({ 6 host: 'localhost', 7 user: 'userName', 8 password: 'secret', 9 database: 'databaseName', 10}); 11 12connection.connect(); 13 14// Mix-in for Data Access Methods and SQL Autogenerating Methods 15mysqlUtilities.upgrade(connection); 16 17// Mix-in for Introspection Methods 18mysqlUtilities.introspection(connection); 19 20// Do something using utilities 21connection.queryRow( 22 'SELECT * FROM _Language where LanguageId=?', 23 [3], 24 (err, row) => { 25 console.dir({ queryRow: row }); 26 } 27); 28 29// Release connection 30connection.end();
Single row selection: connection.queryRow(sql, values, callback) returns hash as callback second parameter, field names becomes hash keys.
1connection.queryRow( 2 'SELECT * FROM Language where LanguageId=?', 3 [3], 4 (err, row) => { 5 console.dir({ queryRow: row }); 6 } 7);
Output:
1queryRow: { 2 LanguageId: 3, 3 LanguageName: 'Russian', 4 LanguageSign: 'ru', 5 LanguageISO: 'ru', 6 Caption: 'Русский' 7}
Single value selection: connection.queryValue(sql, values, callback) returns single value as callback second parameter (instead of array in array). For example, for Id selection by name with LIMIT 1 or count(*), max(field) etc.
1connection.queryValue( 2 'SELECT LanguageName FROM Language where LanguageId=?', 3 [8], 4 (err, name) => { 5 console.dir({ queryValue: name }); 6 } 7);
Output:
1{ 2 queryValue: 'Italiano'; 3}
Single column selection: connection.queryCol(sql, values, callback) returns array as callback second parameter.
1connection.queryCol('SELECT LanguageSign FROM Language', [], (err, result) => { 2 console.dir({ queryCal: result }); 3});
Output:
1queryArray: ['de', 'en', 'es', 'fr', 'it', 'pl', 'ru', 'ua'];
Hash selection: connection.queryHash(sql, values, callback) returns hash as callback second parameter, hash keyed by first field values from SQL statement.
1connection.queryHash( 2 'SELECT LanguageSign, LanguageId, LanguageName, Caption, LanguageISO FROM Language', 3 [], 4 (err, result) => { 5 console.dir({ queryHash: result }); 6 } 7);
Output:
1queryHash: { 2 en: { 3 LanguageSign: 'en', 4 LanguageId: 2, 5 LanguageName: 'English', 6 Caption: 'Английский', 7 LanguageISO: 'en' }, 8 ru: { 9 LanguageSign: 'ru', 10 LanguageId: 3, 11 LanguageName: 'Russian', 12 Caption: 'Русский', 13 LanguageISO: 'ru' }, 14 de: { 15 LanguageSign: 'de', 16 LanguageId: 7, 17 LanguageName: 'Deutsch', 18 Caption: 'Немецкий', 19 LanguageISO: 'de' }, 20 it: { 21 LanguageSign: 'it', 22 LanguageId: 8, 23 LanguageName: 'Italiano', 24 Caption: 'Итальянский', 25 LanguageISO: 'it' 26 } 27}
Key/value pair selection: connection.queryKeyValue(sql, values, callback) returns hash as callback second parameter, hash keyed by first field, values filled by second field.
1connection.queryKeyValue( 2 'SELECT LanguageISO, LanguageName FROM Language', 3 [], 4 (err, keyValue) => { 5 console.dir({ queryKeyValue: keyValue }); 6 } 7);
Output:
1keyValue: { 2 en: 'English', 3 ru: 'Russian', 4 uk: 'Ukrainian', 5 es: 'Espanol', 6 fr: 'Francais', 7 de: 'Deutsch', 8 it: 'Italiano', 9 pl: 'Poliski' 10}
Get primary key list with metadata: connection.primary(table, callback) returns metadata as callback second parameter.
1connection.primary('Language', (err, primary) => { 2 console.dir({ primary }); 3});
Output:
1primary: { 2 Table: 'language', 3 Non_unique: 0, 4 Key_name: 'PRIMARY', 5 Seq_in_index: 1, 6 Column_name: 'LanguageId', 7 Collation: 'A', 8 Cardinality: 9, 9 Sub_part: null, 10 Packed: null, 11 Null: '', 12 Index_type: 'BTREE', 13 Comment: '', 14 Index_comment: '' 15}
Get foreign key list with metadata: connection.foreign(table, callback) returns metadata as callback second parameter.
1connection.foreign('TemplateCaption', (err, foreign) => { 2 console.dir({ foreign }); 3});
Output:
1foreign: { 2 fkTemplateCaptionLanguage: { 3 CONSTRAINT_NAME: 'fkTemplateCaptionLanguage', 4 COLUMN_NAME: 'LanguageId', 5 ORDINAL_POSITION: 1, 6 POSITION_IN_UNIQUE_CONSTRAINT: 1, 7 REFERENCED_TABLE_NAME: 'language', 8 REFERENCED_COLUMN_NAME: 'LanguageId' }, 9 fkTemplateCaptionTemplate: { 10 CONSTRAINT_NAME: 'fkTemplateCaptionTemplate', 11 COLUMN_NAME: 'TemplateId', 12 ORDINAL_POSITION: 1, 13 POSITION_IN_UNIQUE_CONSTRAINT: 1, 14 REFERENCED_TABLE_NAME: 'template', 15 REFERENCED_COLUMN_NAME: 'TemplateId' 16 } 17}
Referential constraints list with metadata: connection.constraints(table, callback).
1connection.constraints('TemplateCaption', (err, constraints) => { 2 console.dir({ constraints }); 3});
Output:
1constraints: { 2 fkTemplateCaptionLanguage: { 3 CONSTRAINT_NAME: 'fkTemplateCaptionLanguage', 4 UNIQUE_CONSTRAINT_NAME: 'PRIMARY', 5 REFERENCED_TABLE_NAME: 'Language', 6 MATCH_OPTION: 'NONE', 7 UPDATE_RULE: 'RESTRICT', 8 DELETE_RULE: 'CASCADE' }, 9 fkTemplateCaptionTemplate: { 10 CONSTRAINT_NAME: 'fkTemplateCaptionTemplate', 11 UNIQUE_CONSTRAINT_NAME: 'PRIMARY', 12 REFERENCED_TABLE_NAME: 'Template', 13 MATCH_OPTION: 'NONE', 14 UPDATE_RULE: 'RESTRICT', 15 DELETE_RULE: 'CASCADE' 16 } 17}
Get table fields with metadata: connection.fields(table, callback).
1connection.fields('Language', (err, fields) => { 2 console.dir({ fields }); 3});
Output:
1fields: { 2 LanguageId: { 3 Field: 'LanguageId', 4 Type: 'int(10) unsigned', 5 Collation: null, 6 Null: 'NO', 7 Key: 'PRI', 8 Default: null, 9 Extra: 'auto_increment', 10 Privileges: 'select,insert,update,references', 11 Comment: 'Id(EN),Код(RU)' }, 12 LanguageName: { 13 Field: 'LanguageName', 14 Type: 'varchar(32)', 15 Collation: 'utf8_general_ci', 16 Null: 'NO', 17 Key: 'UNI', 18 Default: null, 19 Extra: '', 20 Privileges: 'select,insert,update,references', 21 Comment: 'Name(EN),Имя(RU)' 22 }, ... 23}
Get database list for current connection: connection.databases(callback).
1connection.databases((err, databases) => { 2 console.dir({ databases }); 3});
Output:
1databases: [ 2 'information_schema', 3 'mezha', 4 'mysql', 5 'performance_schema', 6 'test', 7];
Get table list for current database: connection.tables(callback).
1connection.tables((err, tables) => { 2 console.dir({ tables }); 3});
Output:
1tables: { 2 Language: { 3 TABLE_NAME: 'Language', 4 TABLE_TYPE: 'BASE TABLE', 5 ENGINE: 'InnoDB', 6 VERSION: 10, 7 ROW_FORMAT: 'Compact', 8 TABLE_ROWS: 9, 9 AVG_ROW_LENGTH: 1820, 10 DATA_LENGTH: 16384, 11 MAX_DATA_LENGTH: 0, 12 INDEX_LENGTH: 49152, 13 DATA_FREE: 8388608, 14 AUTO_INCREMENT: 10, 15 CREATE_TIME: Mon Jul 15 2013 03:06:08 GMT+0300 (Финляндия (лето)), 16 UPDATE_TIME: null, 17 CHECK_TIME: null, 18 TABLE_COLLATION: 'utf8_general_ci', 19 CHECKSUM: null, 20 CREATE_OPTIONS: '', 21 TABLE_COMMENT: '_Language:Languages(EN),Языки(RU)' 22 }, ... 23}
Get table list for specified database: connection.databaseTables(database, callback).
1connection.databaseTables('databaseName', (err, tables) => { 2 console.dir({ databaseTables: tables }); 3});
Output:
1tables: { 2 Language: { 3 TABLE_NAME: 'Language', 4 TABLE_TYPE: 'BASE TABLE', 5 ENGINE: 'InnoDB', 6 VERSION: 10, 7 ROW_FORMAT: 'Compact', 8 TABLE_ROWS: 9, 9 AVG_ROW_LENGTH: 1820, 10 DATA_LENGTH: 16384, 11 MAX_DATA_LENGTH: 0, 12 INDEX_LENGTH: 49152, 13 DATA_FREE: 8388608, 14 AUTO_INCREMENT: 10, 15 CREATE_TIME: Mon Jul 15 2013 03:06:08 GMT+0300 (Финляндия (лето)), 16 UPDATE_TIME: null, 17 CHECK_TIME: null, 18 TABLE_COLLATION: 'utf8_general_ci', 19 CHECKSUM: null, 20 CREATE_OPTIONS: '', 21 TABLE_COMMENT: '_Language:Languages(EN),Языки(RU)' 22 }, ... 23}
Get table metadata: connection.tableInfo(table, callback).
1connection.tableInfo('Language', (err, info) => { 2 console.dir({ tableInfo: info }); 3});
Output:
1tableInfo: { 2 Name: 'language', 3 Engine: 'InnoDB', 4 Version: 10, 5 Row_format: 'Compact', 6 Rows: 9, 7 Avg_row_length: 1820, 8 Data_length: 16384, 9 Max_data_length: 0, 10 Index_length: 49152, 11 Data_free: 9437184, 12 Auto_increment: 10, 13 Create_time: Mon Jul 15 2013 03:06:08 GMT+0300 (Финляндия (лето)), 14 Update_time: null, 15 Check_time: null, 16 Collation: 'utf8_general_ci', 17 Checksum: null, 18 Create_options: '', 19 Comment: '' 20}
Get table indexes metadata: connection.indexes(table, callback).
1connection.indexes('Language', function (err, info) { 2 console.dir({ tableInfo: info }); 3});
Output:
1indexes: { 2 PRIMARY: { 3 Table: 'language', 4 Non_unique: 0, 5 Key_name: 'PRIMARY', 6 Seq_in_index: 1, 7 Column_name: 'LanguageId', 8 Collation: 'A', 9 Cardinality: 9, 10 Sub_part: null, 11 Packed: null, 12 Null: '', 13 Index_type: 'BTREE', 14 Comment: '', 15 Index_comment: '' }, 16 akLanguage: { 17 Table: 'language', 18 Non_unique: 0, 19 Key_name: 'akLanguage', 20 Seq_in_index: 1, 21 Column_name: 'LanguageName', 22 Collation: 'A', 23 Cardinality: 9, 24 Sub_part: null, 25 Packed: null, 26 Null: '', 27 Index_type: 'BTREE', 28 Comment: '', 29 Index_comment: '' 30 } 31}
Get MySQL process list: connection.processes(callback).
1connection.processes(function (err, processes) { 2 console.dir({ processes }); 3});
Output:
1processes: [ 2 { 3 ID: 62, 4 USER: 'mezha', 5 HOST: 'localhost:14188', 6 DB: 'mezha', 7 COMMAND: 'Query', 8 TIME: 0, 9 STATE: 'executing', 10 INFO: 'SELECT * FROM information_schema.PROCESSLIST', 11 }, 12 { 13 ID: 33, 14 USER: 'root', 15 HOST: 'localhost:39589', 16 DB: null, 17 COMMAND: 'Sleep', 18 TIME: 1, 19 STATE: '', 20 INFO: null, 21 }, 22];
Get MySQL global variables: connection.globalVariables(callback)
1connection.globalVariables((err, globalVariables) => { 2 console.dir({ globalVariables }); 3});
Output:
1globalVariables: { 2 MAX_PREPARED_STMT_COUNT: '16382', 3 MAX_JOIN_SIZE: '18446744073709551615', 4 HAVE_CRYPT: 'NO', 5 PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_LONG_SIZE: '10000', 6 INNODB_VERSION: '5.5.32', 7 FLUSH_TIME: '1800', 8 MAX_ERROR_COUNT: '64', 9 ... 10}
Get MySQL global status: connection.globalStatus(callback)
1connection.globalStatus((err, globalStatus) => { 2 console.dir({ globalStatus }); 3});
Output:
1globalStatus: { 2 ABORTED_CLIENTS: '54', 3 ABORTED_CONNECTS: '2', 4 BINLOG_CACHE_DISK_USE: '0', 5 BINLOG_CACHE_USE: '0', 6 BINLOG_STMT_CACHE_DISK_USE: '0', 7 BINLOG_STMT_CACHE_USE: '0', 8 BYTES_RECEIVED: '654871', 9 BYTES_SENT: '212454927', 10 COM_ADMIN_COMMANDS: '594', 11 ... 12}
Get MySQL user list: connection.users(callback)
1connection.users((err, users) => { 2 console.dir({ users }); 3});
Output:
1users: [ 2 { 3 Host: 'localhost', 4 User: 'root', 5 Password: '*90E462C37378CED12064BB3388827D2BA3A9B689', 6 Select_priv: 'Y', 7 Insert_priv: 'Y', 8 Update_priv: 'Y', 9 Delete_priv: 'Y', 10 Create_priv: 'Y', 11 Drop_priv: 'Y', 12 Reload_priv: 'Y', 13 Shutdown_priv: 'Y', 14 Process_priv: 'Y', 15 File_priv: 'Y', 16 Grant_priv: 'Y', 17 References_priv: 'Y', 18 Index_priv: 'Y', 19 Alter_priv: 'Y', 20 Show_db_priv: 'Y', 21 Super_priv: 'Y', 22 Create_tmp_table_priv: 'Y', 23 Lock_tables_priv: 'Y', 24 Execute_priv: 'Y', 25 Repl_slave_priv: 'Y', 26 Repl_client_priv: 'Y', 27 Create_view_priv: 'Y', 28 Show_view_priv: 'Y', 29 Create_routine_priv: 'Y', 30 Alter_routine_priv: 'Y', 31 Create_user_priv: 'Y', 32 Event_priv: 'Y', 33 Trigger_priv: 'Y', 34 Create_tablespace_priv: 'Y', 35 ssl_type: '', 36 ssl_cipher: <Buffer >, 37 x509_issuer: <Buffer >, 38 x509_subject: <Buffer >, 39 max_questions: 0, 40 max_updates: 0, 41 max_connections: 0, 42 max_user_connections: 0, 43 plugin: '', 44 authentication_string: '' 45 }, ... 46]
Generate MySQL WHERE statement: connection.where(conditions), works synchronously, no callback. Returns WHERE statement for given JSON-style conditions.
1const where = connection.where({ 2 id: 5, 3 year: '>2010', 4 price: '100..200', 5 level: '<=3', 6 sn: '*str?', 7 label: 'str', 8 code: '(1,2,4,10,11)', 9}); 10console.dir(where); 11// Output: "id = 5 AND year > '2010' AND (price BETWEEN '100' AND '200') AND 12// level <= '3' AND sn LIKE '%str_' AND label = 'str' AND code IN (1,2,4,10,11)"
Generate SELECT statement: connection.select(table, whereFilter, orderBy, callback)
1connection.select( 2 'Language', 3 '*', 4 { LanguageId: '1..3' }, 5 { LanguageId: 'desc' }, 6 (err, results) => { 7 console.dir({ select: results }); 8 } 9);
Generate INSERT statement: connection.insert(table, row, callback)
1connection.insert( 2 'Language', 3 { 4 LanguageName: 'Tatar', 5 LanguageSign: 'TT', 6 LanguageISO: 'TT', 7 Caption: 'Tatar', 8 }, 9 (err, recordId) => { 10 console.dir({ insert: recordId }); 11 } 12);
Generate UPDATE statement: connection.update(table, row, callback)
1connection.update( 2 'Language', 3 { 4 LanguageId: 25, 5 LanguageName: 'Tatarca', 6 LanguageSign: 'TT', 7 LanguageISO: 'TT', 8 Caption: 'Tatarca', 9 }, 10 (err, affectedRows) => { 11 console.dir({ update: affectedRows }); 12 } 13);
Generate UPDATE statement with "where": connection.update(table, row, where, callback)
1connection.update( 2 'Language', 3 { LanguageSign: 'TT' }, 4 { LanguageId: 1 }, 5 (err, affectedRows) => { 6 console.dir({ update: affectedRows }); 7 } 8);
Generate INSERT statement if record not exists or UPDATE if it exists: connection.upsert(table, row, callback)
1connection.upsert( 2 'Language', 3 { 4 LanguageId: 25, 5 LanguageName: 'Tatarca', 6 LanguageSign: 'TT', 7 LanguageISO: 'TT', 8 Caption: 'Tatarca', 9 }, 10 (err, affectedRows) => { 11 console.dir({ upsert: affectedRows }); 12 } 13);
Get record count: connection.count(table, whereFilter, callback)
1connection.count('Language', { LanguageId: '>3' }, (err, count) => { 2 console.dir({ count }); 3 // count: 9 4});
Generate DELETE statement: connection.delete(table, whereFilter, callback)
1connection.delete('Language', { LanguageSign: 'TT' }, (err, affectedRows) => { 2 console.dir({ delete: affectedRows }); 3});
Copyright (c) 2012-2021 Metarhia <timur.shemsedinov@gmail.com> See github for full contributors list. Node MySql Utilities is MIT licensed.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More