{"id":15041098,"url":"https://github.com/tshemsedinov/node-mysql-utilities","last_synced_at":"2025-04-07T07:07:21.179Z","repository":{"id":11374559,"uuid":"13812480","full_name":"tshemsedinov/node-mysql-utilities","owner":"tshemsedinov","description":"Query builder for node-mysql with introspection, etc.","archived":false,"fork":false,"pushed_at":"2023-07-18T21:19:46.000Z","size":267,"stargazers_count":112,"open_issues_count":12,"forks_count":23,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-31T05:04:47.663Z","etag":null,"topics":["crud","dal","data-access-layer","database","db","introspection","javascript","js","metadata","mysql","node","nodejs","sql","utilities"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tshemsedinov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"tshemsedinov"}},"created_at":"2013-10-23T19:28:49.000Z","updated_at":"2025-03-29T06:44:33.000Z","dependencies_parsed_at":"2024-06-18T15:23:30.409Z","dependency_job_id":"f6970ed7-caf0-4f6b-9851-2e3063476ad6","html_url":"https://github.com/tshemsedinov/node-mysql-utilities","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshemsedinov%2Fnode-mysql-utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshemsedinov%2Fnode-mysql-utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshemsedinov%2Fnode-mysql-utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshemsedinov%2Fnode-mysql-utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tshemsedinov","download_url":"https://codeload.github.com/tshemsedinov/node-mysql-utilities/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608151,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crud","dal","data-access-layer","database","db","introspection","javascript","js","metadata","mysql","node","nodejs","sql","utilities"],"created_at":"2024-09-24T20:45:32.748Z","updated_at":"2025-04-07T07:07:21.157Z","avatar_url":"https://github.com/tshemsedinov.png","language":"JavaScript","funding_links":["https://patreon.com/tshemsedinov"],"categories":[],"sub_categories":[],"readme":"# Node MySql Utilities\n\n[Utilities](https://github.com/tshemsedinov/node-mysql-utilities) for\n[node-mysql driver](https://github.com/felixge/node-mysql) with specialized\nresult types, introspection and other helpful functionality for\n[node.js](http://nodejs.org). Initially this utilities were part of\n[Impress](https://npmjs.org/package/impress) Application Server and\nextracted separately for use with other frameworks.\n\n[![CI Status](https://github.com/tshemsedinov/node-mysql-utilities/workflows/Testing%20CI/badge.svg)](https://github.com/tshemsedinov/node-mysql-utilities/actions?query=workflow%3A%22Testing+CI%22+branch%3Amaster)\n[![NPM Version](https://badge.fury.io/js/mysql-utilities.svg)](https://badge.fury.io/js/mysql-utilities)\n[![NPM Downloads/Month](https://img.shields.io/npm/dm/mysql-utilities.svg)](https://www.npmjs.com/package/mysql-utilities)\n[![NPM Downloads](https://img.shields.io/npm/dt/mysql-utilities.svg)](https://www.npmjs.com/package/mysql-utilities)\n\n![impress logo](http://habrastorage.org/storage3/747/830/b17/747830b1782bd95f28b8d05eff8e05d9.jpg)\n\n## Installation\n\n```bash\n$ npm install mysql-utilities\n```\n\n## Features\n\n- MySQL Data Access Methods\n  - Query selecting single row: connection.queryRow(sql, values, callback)\n  - Query selecting scalar (single value): connection.queryValue(sql, values, callback)\n  - Query selecting column into array: connection.queryCol(sql, values, callback)\n  - Query selecting hash of records: connection.queryHash(sql, values, callback)\n  - Query selecting key/value hash: connection.queryKeyValue(sql, values, callback)\n- MySQL Introspection Methods\n  - Get primary key metadata: connection.primary(table, callback)\n  - Get foreign key metadata: connection.foreign(table, callback)\n  - Get table constraints metadata: connection.constraints(table, callback)\n  - Get table fields metadata: connection.fields(table, callback)\n  - Get connection databases array: connection.databases(callback)\n  - Get database tables list for current db: connection.tables(callback)\n  - Get database tables list for given db: connection.databaseTables(database, callback)\n  - Get table metadata: connection.tableInfo(table, callback)\n  - Get table indexes metadata: connection.indexes(table, callback)\n  - Get server process list: connection.processes(callback)\n  - Get server global variables: connection.globalVariables(callback)\n  - Get server global status: connection.globalStatus(callback)\n  - Get database users: connection.users(callback)\n- MySQL SQL Statements Autogenerating Methods\n  - Selecting record(s): connection.select(table, whereFilter, callback)\n  - Inserting record: connection.insert(table, row, callback)\n  - Updating record: connection.update(table, row, where, callback)\n  - Inserting or selecting record: connection.upsert(table, row, callback)\n  - Count records with filter: connection.count(table, whereFilter, callback)\n  - Delete record(s): connection.delete(table, whereFilter, callback)\n- Events\n  - Catch any query execution: connection.on('query', function(err, res, fields, query) {});\n  - Catch errors: connection.on('error', function(err, query) {});\n  - Catch slow query execution: connection.on('slow', function(err, res, fields, query, executionTime) {});\n\n## Initialization\n\nUtilities can be attached to connection using mix-ins:\n\n```js\n// Library dependencies\nconst mysql = require('mysql');\nconst mysqlUtilities = require('mysql-utilities');\n\nconst connection = mysql.createConnection({\n  host: 'localhost',\n  user: 'userName',\n  password: 'secret',\n  database: 'databaseName',\n});\n\nconnection.connect();\n\n// Mix-in for Data Access Methods and SQL Autogenerating Methods\nmysqlUtilities.upgrade(connection);\n\n// Mix-in for Introspection Methods\nmysqlUtilities.introspection(connection);\n\n// Do something using utilities\nconnection.queryRow(\n  'SELECT * FROM _Language where LanguageId=?',\n  [3],\n  (err, row) =\u003e {\n    console.dir({ queryRow: row });\n  }\n);\n\n// Release connection\nconnection.end();\n```\n\n## Examples\n\nSingle row selection: connection.queryRow(sql, values, callback) returns hash as callback second parameter, field names becomes hash keys.\n\n```js\nconnection.queryRow(\n  'SELECT * FROM Language where LanguageId=?',\n  [3],\n  (err, row) =\u003e {\n    console.dir({ queryRow: row });\n  }\n);\n```\n\nOutput:\n\n```js\nqueryRow: {\n  LanguageId: 3,\n  LanguageName: 'Russian',\n  LanguageSign: 'ru',\n  LanguageISO: 'ru',\n  Caption: 'Русский'\n}\n```\n\nSingle 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.\n\n```js\nconnection.queryValue(\n  'SELECT LanguageName FROM Language where LanguageId=?',\n  [8],\n  (err, name) =\u003e {\n    console.dir({ queryValue: name });\n  }\n);\n```\n\nOutput:\n\n```js\n{\n  queryValue: 'Italiano';\n}\n```\n\nSingle column selection: connection.queryCol(sql, values, callback) returns array as callback second parameter.\n\n```js\nconnection.queryCol('SELECT LanguageSign FROM Language', [], (err, result) =\u003e {\n  console.dir({ queryCal: result });\n});\n```\n\nOutput:\n\n```js\nqueryArray: ['de', 'en', 'es', 'fr', 'it', 'pl', 'ru', 'ua'];\n```\n\nHash selection: connection.queryHash(sql, values, callback) returns hash as callback second parameter, hash keyed by first field values from SQL statement.\n\n```js\nconnection.queryHash(\n  'SELECT LanguageSign, LanguageId, LanguageName, Caption, LanguageISO FROM Language',\n  [],\n  (err, result) =\u003e {\n    console.dir({ queryHash: result });\n  }\n);\n```\n\nOutput:\n\n```js\nqueryHash: {\n  en: {\n    LanguageSign: 'en',\n    LanguageId: 2,\n    LanguageName: 'English',\n    Caption: 'Английский',\n    LanguageISO: 'en' },\n  ru: {\n    LanguageSign: 'ru',\n    LanguageId: 3,\n    LanguageName: 'Russian',\n    Caption: 'Русский',\n    LanguageISO: 'ru' },\n  de: {\n    LanguageSign: 'de',\n    LanguageId: 7,\n    LanguageName: 'Deutsch',\n    Caption: 'Немецкий',\n    LanguageISO: 'de' },\n  it: {\n    LanguageSign: 'it',\n    LanguageId: 8,\n    LanguageName: 'Italiano',\n    Caption: 'Итальянский',\n    LanguageISO: 'it'\n  }\n}\n```\n\nKey/value pair selection: connection.queryKeyValue(sql, values, callback) returns hash as callback second parameter, hash keyed by first field, values filled by second field.\n\n```js\nconnection.queryKeyValue(\n  'SELECT LanguageISO, LanguageName FROM Language',\n  [],\n  (err, keyValue) =\u003e {\n    console.dir({ queryKeyValue: keyValue });\n  }\n);\n```\n\nOutput:\n\n```js\nkeyValue: {\n  en: 'English',\n  ru: 'Russian',\n  uk: 'Ukrainian',\n  es: 'Espanol',\n  fr: 'Francais',\n  de: 'Deutsch',\n  it: 'Italiano',\n  pl: 'Poliski'\n}\n```\n\nGet primary key list with metadata: connection.primary(table, callback) returns metadata as callback second parameter.\n\n```js\nconnection.primary('Language', (err, primary) =\u003e {\n  console.dir({ primary });\n});\n```\n\nOutput:\n\n```js\nprimary: {\n  Table: 'language',\n  Non_unique: 0,\n  Key_name: 'PRIMARY',\n  Seq_in_index: 1,\n  Column_name: 'LanguageId',\n  Collation: 'A',\n  Cardinality: 9,\n  Sub_part: null,\n  Packed: null,\n  Null: '',\n  Index_type: 'BTREE',\n  Comment: '',\n  Index_comment: ''\n}\n```\n\nGet foreign key list with metadata: connection.foreign(table, callback) returns metadata as callback second parameter.\n\n```js\nconnection.foreign('TemplateCaption', (err, foreign) =\u003e {\n  console.dir({ foreign });\n});\n```\n\nOutput:\n\n```js\nforeign: {\n  fkTemplateCaptionLanguage: {\n    CONSTRAINT_NAME: 'fkTemplateCaptionLanguage',\n    COLUMN_NAME: 'LanguageId',\n    ORDINAL_POSITION: 1,\n    POSITION_IN_UNIQUE_CONSTRAINT: 1,\n    REFERENCED_TABLE_NAME: 'language',\n    REFERENCED_COLUMN_NAME: 'LanguageId' },\n  fkTemplateCaptionTemplate: {\n    CONSTRAINT_NAME: 'fkTemplateCaptionTemplate',\n    COLUMN_NAME: 'TemplateId',\n    ORDINAL_POSITION: 1,\n    POSITION_IN_UNIQUE_CONSTRAINT: 1,\n    REFERENCED_TABLE_NAME: 'template',\n    REFERENCED_COLUMN_NAME: 'TemplateId'\n  }\n}\n```\n\nReferential constraints list with metadata: connection.constraints(table, callback).\n\n```js\nconnection.constraints('TemplateCaption', (err, constraints) =\u003e {\n  console.dir({ constraints });\n});\n```\n\nOutput:\n\n```js\nconstraints: {\n  fkTemplateCaptionLanguage: {\n    CONSTRAINT_NAME: 'fkTemplateCaptionLanguage',\n    UNIQUE_CONSTRAINT_NAME: 'PRIMARY',\n    REFERENCED_TABLE_NAME: 'Language',\n    MATCH_OPTION: 'NONE',\n    UPDATE_RULE: 'RESTRICT',\n    DELETE_RULE: 'CASCADE' },\n  fkTemplateCaptionTemplate: {\n    CONSTRAINT_NAME: 'fkTemplateCaptionTemplate',\n    UNIQUE_CONSTRAINT_NAME: 'PRIMARY',\n    REFERENCED_TABLE_NAME: 'Template',\n    MATCH_OPTION: 'NONE',\n    UPDATE_RULE: 'RESTRICT',\n    DELETE_RULE: 'CASCADE'\n  }\n}\n```\n\nGet table fields with metadata: connection.fields(table, callback).\n\n```js\nconnection.fields('Language', (err, fields) =\u003e {\n  console.dir({ fields });\n});\n```\n\nOutput:\n\n```js\nfields: {\n  LanguageId: {\n    Field: 'LanguageId',\n    Type: 'int(10) unsigned',\n    Collation: null,\n    Null: 'NO',\n    Key: 'PRI',\n    Default: null,\n    Extra: 'auto_increment',\n    Privileges: 'select,insert,update,references',\n    Comment: 'Id(EN),Код(RU)' },\n  LanguageName: {\n    Field: 'LanguageName',\n    Type: 'varchar(32)',\n    Collation: 'utf8_general_ci',\n    Null: 'NO',\n    Key: 'UNI',\n    Default: null,\n    Extra: '',\n    Privileges: 'select,insert,update,references',\n    Comment: 'Name(EN),Имя(RU)'\n  }, ...\n}\n```\n\nGet database list for current connection: connection.databases(callback).\n\n```js\nconnection.databases((err, databases) =\u003e {\n  console.dir({ databases });\n});\n```\n\nOutput:\n\n```js\ndatabases: [\n  'information_schema',\n  'mezha',\n  'mysql',\n  'performance_schema',\n  'test',\n];\n```\n\nGet table list for current database: connection.tables(callback).\n\n```js\nconnection.tables((err, tables) =\u003e {\n  console.dir({ tables });\n});\n```\n\nOutput:\n\n```js\ntables: {\n  Language: {\n    TABLE_NAME: 'Language',\n    TABLE_TYPE: 'BASE TABLE',\n    ENGINE: 'InnoDB',\n    VERSION: 10,\n    ROW_FORMAT: 'Compact',\n    TABLE_ROWS: 9,\n    AVG_ROW_LENGTH: 1820,\n    DATA_LENGTH: 16384,\n    MAX_DATA_LENGTH: 0,\n    INDEX_LENGTH: 49152,\n    DATA_FREE: 8388608,\n    AUTO_INCREMENT: 10,\n    CREATE_TIME: Mon Jul 15 2013 03:06:08 GMT+0300 (Финляндия (лето)),\n    UPDATE_TIME: null,\n    CHECK_TIME: null,\n    TABLE_COLLATION: 'utf8_general_ci',\n    CHECKSUM: null,\n    CREATE_OPTIONS: '',\n    TABLE_COMMENT: '_Language:Languages(EN),Языки(RU)'\n  }, ...\n}\n```\n\nGet table list for specified database: connection.databaseTables(database, callback).\n\n```js\nconnection.databaseTables('databaseName', (err, tables) =\u003e {\n  console.dir({ databaseTables: tables });\n});\n```\n\nOutput:\n\n```js\ntables: {\n  Language: {\n    TABLE_NAME: 'Language',\n    TABLE_TYPE: 'BASE TABLE',\n    ENGINE: 'InnoDB',\n    VERSION: 10,\n    ROW_FORMAT: 'Compact',\n    TABLE_ROWS: 9,\n    AVG_ROW_LENGTH: 1820,\n    DATA_LENGTH: 16384,\n    MAX_DATA_LENGTH: 0,\n    INDEX_LENGTH: 49152,\n    DATA_FREE: 8388608,\n    AUTO_INCREMENT: 10,\n    CREATE_TIME: Mon Jul 15 2013 03:06:08 GMT+0300 (Финляндия (лето)),\n    UPDATE_TIME: null,\n    CHECK_TIME: null,\n    TABLE_COLLATION: 'utf8_general_ci',\n    CHECKSUM: null,\n    CREATE_OPTIONS: '',\n    TABLE_COMMENT: '_Language:Languages(EN),Языки(RU)'\n  }, ...\n}\n```\n\nGet table metadata: connection.tableInfo(table, callback).\n\n```js\nconnection.tableInfo('Language', (err, info) =\u003e {\n  console.dir({ tableInfo: info });\n});\n```\n\nOutput:\n\n```js\ntableInfo: {\n  Name: 'language',\n  Engine: 'InnoDB',\n  Version: 10,\n  Row_format: 'Compact',\n  Rows: 9,\n  Avg_row_length: 1820,\n  Data_length: 16384,\n  Max_data_length: 0,\n  Index_length: 49152,\n  Data_free: 9437184,\n  Auto_increment: 10,\n  Create_time: Mon Jul 15 2013 03:06:08 GMT+0300 (Финляндия (лето)),\n  Update_time: null,\n  Check_time: null,\n  Collation: 'utf8_general_ci',\n  Checksum: null,\n  Create_options: '',\n  Comment: ''\n}\n```\n\nGet table indexes metadata: connection.indexes(table, callback).\n\n```js\nconnection.indexes('Language', function (err, info) {\n  console.dir({ tableInfo: info });\n});\n```\n\nOutput:\n\n```js\nindexes: {\n  PRIMARY: {\n    Table: 'language',\n    Non_unique: 0,\n    Key_name: 'PRIMARY',\n    Seq_in_index: 1,\n    Column_name: 'LanguageId',\n    Collation: 'A',\n    Cardinality: 9,\n    Sub_part: null,\n    Packed: null,\n    Null: '',\n    Index_type: 'BTREE',\n    Comment: '',\n    Index_comment: '' },\n  akLanguage: {\n    Table: 'language',\n    Non_unique: 0,\n    Key_name: 'akLanguage',\n    Seq_in_index: 1,\n    Column_name: 'LanguageName',\n    Collation: 'A',\n    Cardinality: 9,\n    Sub_part: null,\n    Packed: null,\n    Null: '',\n    Index_type: 'BTREE',\n    Comment: '',\n    Index_comment: ''\n  }\n}\n```\n\nGet MySQL process list: connection.processes(callback).\n\n```js\nconnection.processes(function (err, processes) {\n  console.dir({ processes });\n});\n```\n\nOutput:\n\n```js\nprocesses: [\n  {\n    ID: 62,\n    USER: 'mezha',\n    HOST: 'localhost:14188',\n    DB: 'mezha',\n    COMMAND: 'Query',\n    TIME: 0,\n    STATE: 'executing',\n    INFO: 'SELECT * FROM information_schema.PROCESSLIST',\n  },\n  {\n    ID: 33,\n    USER: 'root',\n    HOST: 'localhost:39589',\n    DB: null,\n    COMMAND: 'Sleep',\n    TIME: 1,\n    STATE: '',\n    INFO: null,\n  },\n];\n```\n\nGet MySQL global variables: connection.globalVariables(callback)\n\n```js\nconnection.globalVariables((err, globalVariables) =\u003e {\n  console.dir({ globalVariables });\n});\n```\n\nOutput:\n\n```js\nglobalVariables: {\n  MAX_PREPARED_STMT_COUNT: '16382',\n  MAX_JOIN_SIZE: '18446744073709551615',\n  HAVE_CRYPT: 'NO',\n  PERFORMANCE_SCHEMA_EVENTS_WAITS_HISTORY_LONG_SIZE: '10000',\n  INNODB_VERSION: '5.5.32',\n  FLUSH_TIME: '1800',\n  MAX_ERROR_COUNT: '64',\n  ...\n}\n```\n\nGet MySQL global status: connection.globalStatus(callback)\n\n```js\nconnection.globalStatus((err, globalStatus) =\u003e {\n  console.dir({ globalStatus });\n});\n```\n\nOutput:\n\n```js\nglobalStatus: {\n  ABORTED_CLIENTS: '54',\n  ABORTED_CONNECTS: '2',\n  BINLOG_CACHE_DISK_USE: '0',\n  BINLOG_CACHE_USE: '0',\n  BINLOG_STMT_CACHE_DISK_USE: '0',\n  BINLOG_STMT_CACHE_USE: '0',\n  BYTES_RECEIVED: '654871',\n  BYTES_SENT: '212454927',\n  COM_ADMIN_COMMANDS: '594',\n  ...\n}\n```\n\nGet MySQL user list: connection.users(callback)\n\n```js\nconnection.users((err, users) =\u003e {\n  console.dir({ users });\n});\n```\n\nOutput:\n\n```js\nusers: [\n  {\n    Host: 'localhost',\n    User: 'root',\n    Password: '*90E462C37378CED12064BB3388827D2BA3A9B689',\n    Select_priv: 'Y',\n    Insert_priv: 'Y',\n    Update_priv: 'Y',\n    Delete_priv: 'Y',\n    Create_priv: 'Y',\n    Drop_priv: 'Y',\n    Reload_priv: 'Y',\n    Shutdown_priv: 'Y',\n    Process_priv: 'Y',\n    File_priv: 'Y',\n    Grant_priv: 'Y',\n    References_priv: 'Y',\n    Index_priv: 'Y',\n    Alter_priv: 'Y',\n    Show_db_priv: 'Y',\n    Super_priv: 'Y',\n    Create_tmp_table_priv: 'Y',\n    Lock_tables_priv: 'Y',\n    Execute_priv: 'Y',\n    Repl_slave_priv: 'Y',\n    Repl_client_priv: 'Y',\n    Create_view_priv: 'Y',\n    Show_view_priv: 'Y',\n    Create_routine_priv: 'Y',\n    Alter_routine_priv: 'Y',\n    Create_user_priv: 'Y',\n    Event_priv: 'Y',\n    Trigger_priv: 'Y',\n    Create_tablespace_priv: 'Y',\n    ssl_type: '',\n    ssl_cipher: \u003cBuffer \u003e,\n    x509_issuer: \u003cBuffer \u003e,\n    x509_subject: \u003cBuffer \u003e,\n    max_questions: 0,\n    max_updates: 0,\n    max_connections: 0,\n    max_user_connections: 0,\n    plugin: '',\n    authentication_string: ''\n  }, ...\n]\n```\n\nGenerate MySQL WHERE statement: connection.where(conditions), works synchronously, no callback. Returns WHERE statement for given JSON-style conditions.\n\n```js\nconst where = connection.where({\n  id: 5,\n  year: '\u003e2010',\n  price: '100..200',\n  level: '\u003c=3',\n  sn: '*str?',\n  label: 'str',\n  code: '(1,2,4,10,11)',\n});\nconsole.dir(where);\n// Output: \"id = 5 AND year \u003e '2010' AND (price BETWEEN '100' AND '200') AND\n// level \u003c= '3' AND sn LIKE '%str_' AND label = 'str' AND code IN (1,2,4,10,11)\"\n```\n\nGenerate SELECT statement: connection.select(table, whereFilter, orderBy, callback)\n\n```js\nconnection.select(\n  'Language',\n  '*',\n  { LanguageId: '1..3' },\n  { LanguageId: 'desc' },\n  (err, results) =\u003e {\n    console.dir({ select: results });\n  }\n);\n```\n\nGenerate INSERT statement: connection.insert(table, row, callback)\n\n```js\nconnection.insert(\n  'Language',\n  {\n    LanguageName: 'Tatar',\n    LanguageSign: 'TT',\n    LanguageISO: 'TT',\n    Caption: 'Tatar',\n  },\n  (err, recordId) =\u003e {\n    console.dir({ insert: recordId });\n  }\n);\n```\n\nGenerate UPDATE statement: connection.update(table, row, callback)\n\n```js\nconnection.update(\n  'Language',\n  {\n    LanguageId: 25,\n    LanguageName: 'Tatarca',\n    LanguageSign: 'TT',\n    LanguageISO: 'TT',\n    Caption: 'Tatarca',\n  },\n  (err, affectedRows) =\u003e {\n    console.dir({ update: affectedRows });\n  }\n);\n```\n\nGenerate UPDATE statement with \"where\": connection.update(table, row, where, callback)\n\n```js\nconnection.update(\n  'Language',\n  { LanguageSign: 'TT' },\n  { LanguageId: 1 },\n  (err, affectedRows) =\u003e {\n    console.dir({ update: affectedRows });\n  }\n);\n```\n\nGenerate INSERT statement if record not exists or UPDATE if it exists: connection.upsert(table, row, callback)\n\n```js\nconnection.upsert(\n  'Language',\n  {\n    LanguageId: 25,\n    LanguageName: 'Tatarca',\n    LanguageSign: 'TT',\n    LanguageISO: 'TT',\n    Caption: 'Tatarca',\n  },\n  (err, affectedRows) =\u003e {\n    console.dir({ upsert: affectedRows });\n  }\n);\n```\n\nGet record count: connection.count(table, whereFilter, callback)\n\n```js\nconnection.count('Language', { LanguageId: '\u003e3' }, (err, count) =\u003e {\n  console.dir({ count });\n  // count: 9\n});\n```\n\nGenerate DELETE statement: connection.delete(table, whereFilter, callback)\n\n```js\nconnection.delete('Language', { LanguageSign: 'TT' }, (err, affectedRows) =\u003e {\n  console.dir({ delete: affectedRows });\n});\n```\n\n## License \u0026 Contributors\n\nCopyright (c) 2012-2023 Metarhia \u0026lt;timur.shemsedinov@gmail.com\u0026gt;\nSee github for full [contributors list](https://github.com/tshemsedinov/node-mysql-utilities/graphs/contributors).\nNode MySql Utilities is [MIT licensed](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftshemsedinov%2Fnode-mysql-utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftshemsedinov%2Fnode-mysql-utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftshemsedinov%2Fnode-mysql-utilities/lists"}