{"id":21342713,"url":"https://github.com/tboydston/wrapsql","last_synced_at":"2026-05-07T12:31:05.211Z","repository":{"id":55652388,"uuid":"321549102","full_name":"tboydston/wrapsql","owner":"tboydston","description":"A MySQL wrapper that allows you to perform basic CRUD updates on a DB without writing any SQL. Results are returned as promises allowing the use of 'await' when synchronous requests are required.","archived":false,"fork":false,"pushed_at":"2021-07-30T08:43:28.000Z","size":2215,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T03:12:07.910Z","etag":null,"topics":["mysql","nodejs","pdo","pdo-mysql","wrapper"],"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/tboydston.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":"2020-12-15T04:09:01.000Z","updated_at":"2021-07-30T08:43:31.000Z","dependencies_parsed_at":"2022-08-15T05:40:11.748Z","dependency_job_id":null,"html_url":"https://github.com/tboydston/wrapsql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tboydston/wrapsql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tboydston%2Fwrapsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tboydston%2Fwrapsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tboydston%2Fwrapsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tboydston%2Fwrapsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tboydston","download_url":"https://codeload.github.com/tboydston/wrapsql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tboydston%2Fwrapsql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32737610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["mysql","nodejs","pdo","pdo-mysql","wrapper"],"created_at":"2024-11-22T01:09:44.574Z","updated_at":"2026-05-07T12:31:05.195Z","avatar_url":"https://github.com/tboydston.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WrapSQL ( wrapsequel )\n\nA MySQL wrapper that allows you to perform basic CRUD updates on a DB without writing any SQL. Results are returned as promises allowing the uses of 'await' when synchronous request are required. \n\u003cbr\u003e\u003cbr\u003e\n\n## Getting Started\n\u003cbr\u003e\n\n```\nnpm install wrapsequel \n```\n\nYou can either pass Wrapsql an active MySQL connection or just the connection settings and Wrapsql will create it's own.\n\n\n### Wrapsql builds MySQL connection\n\u003cbr\u003e\n\n```\nconst Wrapsql = require('wrapsequel')\n\nconst config = {\n    host: '127.0.0.1',\n    port: '8889',\n    user: 'user',\n    password: 'password',\n    database: 'database'\n}\n\nconst wsql = new Wrapsql(config,true)\n\nlet result = await wsql.selectAll('testTable')\nconsole.log( result )\n\n```\n\n### MySQL connection is built and passed to Wrapsql\n\u003cbr\u003e\n\n```\nconst mysql = require('mysql')\nconst Wrapsql = require('wrapsequel')\n\nconst sql = mysql.createConnection({\n    host: '127.0.0.1',\n    port: '8889',\n    user: 'user',\n    password: 'password',\n    database: 'database'\n}) \n\nconst wsql = new Wrapsql(sql,true)\n\nlet result = await wsql.selectAll('testTable')\nconsole.log( result )\n\n```\n\n### CRUD Example\n\nBelow is an example for of how to insert, select, update, and delete a record. \n\n```\n\n\nlet insertResult = await wsql.insert(\"customers\",{firstName:\"Bob\",lastName:\"Smith\",favoriteAnimal:\"dog\"})\n// Equivalent SQL: INSERT INTO customers (firstName, lastName, favoriteAnimal) VALUES ('Bob', 'Smith', 'dog') \n\n// Insert Result:  {\n//   fieldCount: 0,\n//   affectedRows: 1,\n//   insertId: 1,\n//   serverStatus: 2,\n//   warningCount: 0,\n//   message: '',\n//   protocol41: true,\n//   changedRows: 0\n// }\n\n\n// Results can be returned either using async/await or then/catch promise syntax \n\nlet selectResult = {}\n\ntry {\n    selectResult = await wsql.select(\"customers\",\"*\",{firstName:\"Bob\",lastName:\"Smith\"})\n    // Equivalent SQL: SELECT  * FROM customers WHERE firstName = 'Bob' AND lastName = 'Smith' \n} catch(error) {\n    console.log(error)\n}\n\nconsole.log(selectResult)\n\n// OR \n\nwsql.select(\"customers\",\"*\",{firstName:\"Bob\",lastName:\"Smith\"}).then(\n        result=\u003e{selectResult=result}\n    ).catch(error=\u003e{\n        console.log(error)\n    })\n\n\n// Select Result: [\n//   {\n//     id: 1,\n//     firstName: 'Bob',\n//     lastName: 'Smith',\n//     favoriteAnimal: 'dog'\n//   }\n// ]\n\n\nlet updateResult = await wsql.update(\"customers\",{favoriteAnimal:\"cat\"},{id:1})\n// Equivalent SQL: UPDATE customers SET favoriteAnimal = 'cat' WHERE id = 1 \n\n// Update Result: {\n//   fieldCount: 0,\n//   affectedRows: 1,\n//   insertId: 0,\n//   serverStatus: 2,\n//   warningCount: 0,\n//   message: '(Rows matched: 1  Changed: 1  Warnings: 0',\n//   protocol41: true,\n//   changedRows: 1\n// }\n\n\nlet deleteResult = await wsql.delete(\"customers\",{id:1})\n// Equivalent SQL: DELETE FROM customers WHERE id = 1 \n\n// Delete Result: {\n//   fieldCount: 0,\n//   affectedRows: 1,\n//   insertId: 0,\n//   serverStatus: 2,\n//   warningCount: 0,\n//   message: '',\n//   protocol41: true,\n//   changedRows: 0\n// }\n\n    \n```\n\n## Functions\n\n\u003cbr\u003e\n\n### **selectAll(tableName)**\n\n\u003cbr\u003e\n\nSelect all results from a table.\n\n**tableName:** Name of table \n\n### Example\n\n```\n\nlet result = await wsql.selectAll('testTable')\n\n```\n\n\n\u003cbr\u003e\n\n### **select( table, columns, where, orderBy=false, order='ASC', limit=false, offset=false )**\n\n\u003cbr\u003e\n\nSelect data from a table. \u003cbr\u003e\u003cbr\u003e\n**table:** Table to select from.\u003cbr\u003e\n**columns:** Accepts either an array of columns to return or '*' to return all columns. \u003cbr\u003e\n**where:** Object of where conditions, Array defining custom comparison, or string of custom where conditions. Default comparison is 'AND' default operator '='. See  examples below for details.). May Be False to exclude.\u003cbr\u003e\n**orderBy:** Column you would like to order by.  May Be False to exclude.\u003cbr\u003e\n**order:** Order of results ('ASC','DESC').  May Be False to exclude.\u003cbr\u003e\n**limit:** Number of results to return.  May Be False to exclude.\u003cbr\u003e\n**offset:** Number of rows to offset before return results.  May Be False to exclude.\u003cbr\u003e\n**groupBy:** Column to group results by.  May Be False to exclude.\u003cbr\u003e\n\n**where:** comparisons can be represented the following ways. \n\n```\n\n// Default 'AND' comparison\n{column1:value,colum2:value}\n// SQL Result: WHERE column1=value AND column2:value\n\n// Defined 'AND' comparison \n[\"AND\",{column1:value,colum2:value}]\n// SQL Result: WHERE column1=value AND column2:value\n\n// Defined 'OR' comparison \n[\"OR\",{column1:value,colum2:value}]\n// SQL Result: WHERE column1=value OR column2:value\n\n// Defined 'IN' comparison \n[\"IN\",{column1:[value1,value2]}]\n// SQL Result: WHERE column1 IN ('value1','value2')\n\n// Defined operator \n{column1:[\"\u003e\",value],colum2:[\"\u003c\",value]}\n// SQL Result: WHERE column1\u003evalue AND column2\u003cvalue\n\n// Customer WHERE string \n`column1\u003evalue AND column2 IS NOT null OR column2 = 'test'`\n// SQL Result: WHERE column1\u003evalue AND column2 IS NOT null OR column2 = 'test'\n\n```\n\n### Example\n\n```\n // Equivalent SQL: SELECT 'value' FROM 'testTable' WHERE value='testValue' GROUP BY 'value' ORDER BY 'id' DESC LIMIT 10\n let result = await wsql.select('testTable','value',{value:\"testValue\"},\"id\",\"DESC\",10,offset=false,value)\n```\n\n\u003cbr\u003e\n\n### **insert(table,insert)**\n\n\u003cbr\u003e\n\nInsert data into a table. \u003cbr\u003e\u003cbr\u003e\n**table:** Table to select from.\u003cbr\u003e\n**insert:** Object of values to insert {column:\"value\"} or array of Objects to insert multiple rows.\u003cbr\u003e\n\n### Example\n\n```\n// Single row insert.\nlet result = await wsql.insert('insertTest',{testData:\"testInsert\"})\n// Multiple row insert.\nlet result2 = await wsql.insert('insertTest',[{testData:\"testInsert1\"},{testData:\"testInsert2\"}])\n\n```\n\n\n\n\u003cbr\u003e\n\n### **update(table,set,where=false)**\n\n\u003cbr\u003e\n\nUpdate records \u003cbr\u003e\u003cbr\u003e\n**table:** Table to update.\u003cbr\u003e\n**set:** Object of values to set {column:\"value\"} \u003cbr\u003e\n**where:** Object of where conditions. May Be False\u003cbr\u003e\n\n### Example\n\n```\n\nlet result = await wsql.update('insertTest',{value:'updated'},{value:'1'})\n\n```\n\n\n\u003cbr\u003e\n\n### **delete(table,where=false)**\n\n\u003cbr\u003e\n\nDelete records. \u003cbr\u003e\u003cbr\u003e\n**table:** Table to delete records from.\u003cbr\u003e\n**where:** Object of where conditions. May Be False\u003cbr\u003e\n\n### Example\n\n```\n\nlet result = await wsql.delete('insertTest',{value:'1'})\n\n```\n\n\n\u003cbr\u003e\n\n### **count(table,where=false,label)**\n\n\u003cbr\u003e\n\nCount rows in result.\u003cbr\u003e\u003cbr\u003e\n**table:** Table to delete records from.\u003cbr\u003e\n**where:** Object of where conditions. May Be False\u003cbr\u003e\n**label:** Label for count results.\u003cbr\u003e\n\n\n### Example\n\n```\n\nlet result = await wsql.count('testTable',{value:'testRow2'},'theCount')\n\n```\n\n\n\u003cbr\u003e\n\n### **transaction(queries)**\n\n\u003cbr\u003e\n\nSubmit an array of dependant SQL queries to be executed in one request. If one fails they are all rolled back. Results is returned as array of arrays.\u003cbr\u003e\u003cbr\u003e\n**queries:** Array of SQL queries.\u003cbr\u003e\n\n### Example\n\n```\n\nlet queries = [\n    \"SELECT * FROM testTable ORDER BY id DESC\",\n    \"SELECT * FROM testTable\",\n]\n\nlet result = await wsql.transaction(queries)\n\n// result[0] first queries results. \n// result[1] second queries results.   \n\n```\n\n\n\u003cbr\u003e\n\n### **query(query)**\n\n\u003cbr\u003e\n\nPass through a raw SQL query.\u003cbr\u003e\u003cbr\u003e\n**query:** SQL query\u003cbr\u003e\n\n### Example\n\n```\n\nlet query = \"SELECT * FROM testTable ORDER BY id DESC\"\n\nlet result = await wsql.transaction(query)\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftboydston%2Fwrapsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftboydston%2Fwrapsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftboydston%2Fwrapsql/lists"}