{"id":16834726,"url":"https://github.com/mscdex/node-poormansmysql","last_synced_at":"2025-04-11T04:35:19.041Z","repository":{"id":888872,"uuid":"638006","full_name":"mscdex/node-poormansmysql","owner":"mscdex","description":"MySQL driver module for node.js that executes queries using the mysql command-line client.","archived":false,"fork":false,"pushed_at":"2010-05-04T06:23:50.000Z","size":104,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T04:35:16.528Z","etag":null,"topics":[],"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/mscdex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-04-29T11:18:22.000Z","updated_at":"2021-10-31T02:55:37.000Z","dependencies_parsed_at":"2022-07-05T20:31:56.728Z","dependency_job_id":null,"html_url":"https://github.com/mscdex/node-poormansmysql","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/mscdex%2Fnode-poormansmysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fnode-poormansmysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fnode-poormansmysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fnode-poormansmysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mscdex","download_url":"https://codeload.github.com/mscdex/node-poormansmysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345258,"owners_count":21088231,"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":[],"created_at":"2024-10-13T12:07:36.979Z","updated_at":"2025-04-11T04:35:18.977Z","avatar_url":"https://github.com/mscdex.png","language":"JavaScript","readme":"# node-poormansmysql\n\nnode-poormansmysql is a MySQL driver for [node.js](http://nodejs.org/) that executes queries using the mysql command-line client.\n\n\n# Requirements\n\n* [node.js 0.1.92+](http://nodejs.org/)\n* [libxmljs](http://github.com/polotek/libxmljs) -- tested with [7903666cd29001b19fb0](http://github.com/polotek/libxmljs/commit/7903666cd29001b19fb0821f62bcf50f6b5576b3)\n    * Note: libxmljs.node should be placed in the same directory as the node-poormansmysql.js module.\n\n\n# Documentation\n\nMysqlConnection Methods:\n\n* (constructor) **MysqlConnection**(_config_)\n    * **Description**: Performs initialization and sets the connection configuration. All properties supplied in _config_ overwrite the defaults listed below.\n    * **Parameters**:\n         * _config_: (Object) An object containing the necessary connection information to connect to the MySQL server and perform queries. At least the user and password should be supplied. The default configuration is:\n\n                user: null,\n                password: null,\n                db: null,\n                host: 'localhost',\n                port: 3306,\n\t\t\t\tforce: false, // execute ALL queries in the case of a query error\n                connect_timeout: 0, // the time to wait for a connection to the MySQL server (in seconds)\n                execute_timeout: 0 // the time to wait for ALL queries to execute (in seconds) (TODO)\n    * **Return Value**: (MysqlConnection) An instance of MysqlConnection.\n* **setConfig**(_config_)\n    * **Description**: Sets the connection configuration. This is only needed if you are reusing the instance and need to change the connection information. As with the constructor, all properties supplied in _config_ are merged with the defaults.\n    * **Parameters**: \n        * _config_: (Object) An object containing the necessary connection information to connect to the MySQL server and perform queries. At least the user and password should be supplied. See above for the default configuration.\n    * **Return Value**: None\n* **query**(_sql_ [, _cbRow_[, _cbComplete_[, _cbError_]]])\n    * **Description**: Enqueues an SQL statement.\n    * **Parameters**:\n        * _sql_: (String) A valid SQL statement. Do not include a trailing semicolon at the end of the statement.\n        * _cbRow_ (Optional): (Function) A callback for when a row resulted from the query.\n            * **Parameters**:\n                * _row_: (Object) A hash containing a single row from the results of the query.\n        * _cbComplete_ (Optional): (Function) A callback for when the query has completed and all rows have been returned.\n            * **Parameters**:\n                * _totalRows_: (Integer) The total number of rows returned by the query.\n        * _cbError_ (Optional): (Function) A callback for when the query results in a MySQL error.\n            * **Parameters**:\n                * _err_: (String) The entire MySQL error message.\n    * **Return Value**: None\n* **execute**([_cbQueriesComplete_])\n    * **Description**: Begins executing the enqueued SQL statements all at once.\n    * **Parameters**:\n        * _cbQueriesComplete_ (Optional): (Function) A callback that is called when each query in the queue has completed.\n            * **Parameters**: None\n    * **Return Value**: (Boolean) _true_ if there were statements to be executed and the 'user' and 'password' connection details have been supplied, _false_ otherwise.\n* (getter) **affectedRows**\n    * **Description**: Returns the number of rows updated, inserted, or deleted by the last SQL statement.\n    * **Return Value**: (Integer) The number of rows affected by the last SQL statement.\n* (getter) **lastInsertId**\n    * **Description**: Returns the first automatically generated value that was set for an AUTO_INCREMENT column by the most recent INSERT statement. See [here](http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id) for more details.\n    * **Return Value**: (Integer) The value of the AUTO_INCREMENT column for the last INSERTed row.\n* (getter) **lastError**\n    * **Description**: Returns the last error set by the MysqlConnection instance (either a child process spawn error or a MySQL error).\n    * **Return Value**: (String) The value of the last error.\n\nMysqlConnection Events:\n\n* **error**\n    * **Description**: Fired when an error occurs. This can be either a non-query-specific (i.e. system or server-specific) MySQL error or a child process spawning error.\n    * **Parameters**:\n        * _err_: (String) The error details.\n\nUtility methods exposed:\n\n* **escape**(str)\n    * **Description**: Performs \u003cu\u003ebasic\u003c/u\u003e string escaping, similar to the PHP function mysql_escape_string.\n    * **Parameters**:\n        * _str_: (String) The string to escape.\n\n\n# Example\n\n    var pmm = require('./node-poormansmysql'), sys = require('sys');\n\n\tvar fieldvalue = \"o'reilly\";\n    var conn = new pmm.MysqlConnection({user: 'foo', password: 'bar', db: 'baz'});\n\n    conn.addListener('error', function(err) {\n    \tsys.puts('Uh oh, ' + err);\n    });\n\n    conn.query(\"SELECT * FROM table\",\n    \tfunction(row) {\n    \t\tsys.puts(\"Got result for first query: \" + JSON.stringify(row));\n    \t},\n    \tfunction(totalRows) {\n    \t\tsys.puts(\"First query is done! Retrieved \" + totalRows + \" row(s)\");\n    \t},\n    \tfunction(err) {\n    \t\tsys.puts(\"First query resulted in error: \" + err);\n    \t}\n    );\n    conn.query(\"SELECT * FROM table2 WHERE field = '\" + pmm.escape(fieldvalue) + \"'\",\n    \tfunction(row) {\n    \t\tsys.puts(\"Got result for second query: \" + JSON.stringify(row));\n    \t},\n    \tfunction(totalRows) {\n    \t\tsys.puts(\"Second query is done! Retrieved \" + totalRows + \" row(s)\");\n    \t},\n    \tfunction(err) {\n    \t\tsys.puts(\"Second query resulted in error: \" + err);\n    \t}\n    );\n    conn.execute();\n\n\n# License\n\nSee LICENSE file.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fnode-poormansmysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmscdex%2Fnode-poormansmysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fnode-poormansmysql/lists"}