{"id":26283447,"url":"https://github.com/nathanfrancy/mybutler","last_synced_at":"2026-05-09T13:33:35.656Z","repository":{"id":57306473,"uuid":"119280902","full_name":"nathanfrancy/mybutler","owner":"nathanfrancy","description":"When all you need is simple mysql queries to get it done.","archived":false,"fork":false,"pushed_at":"2018-01-28T22:56:59.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T08:39:21.886Z","etag":null,"topics":["database","mysql"],"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/nathanfrancy.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":"2018-01-28T17:25:34.000Z","updated_at":"2018-01-28T23:11:57.000Z","dependencies_parsed_at":"2022-09-20T22:45:57.775Z","dependency_job_id":null,"html_url":"https://github.com/nathanfrancy/mybutler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanfrancy%2Fmybutler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanfrancy%2Fmybutler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanfrancy%2Fmybutler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanfrancy%2Fmybutler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanfrancy","download_url":"https://codeload.github.com/nathanfrancy/mybutler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243615569,"owners_count":20319733,"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":["database","mysql"],"created_at":"2025-03-14T17:18:45.909Z","updated_at":"2026-05-09T13:33:30.613Z","avatar_url":"https://github.com/nathanfrancy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# my(sql)butler 🕴️\n\nWhen all you need is simple mysql queries to get it done.\n\n## Install \n\n``` bash\nnpm install --save mybutler\n```\n\n## Setup\n\nIf you don't already, you'll need to install mysql and create your database and tables.\n\nRefer to the `samples` folder for some examples. Otherwise this is basically all you need to get started: \n\n```javascript\nlet MyButler = require('mybutler');\n\nlet butler = MyButler({\n    connection: {           // Put your connection variables here.\n        host: '',\n        user: '',\n        password: '',\n        database: ''\n    },\n    tables: [               // Put all of the tables you want access to here\n        \"users\", \n        \"user_logs\"\n    ],\n    log: true,              // Optionally, turn mybutler's internal logging on\n    logger: console.log     // Optionally, replace the logging function, this only applies if you have set \"log\" to true\n});\n```\n\n## Usage\nYou can do this differently, but I new up the object above in a separate file, then require it to other places I want to use it, and use the helper methods like this: \n\n```javascript\nlet butler = require('./path/to/butler');\n\n// Each table is namespaced by the name you gave in the config.\nbutler.users.insert(...)...\nbutler.user_logs.getOneWhere(...)...\n```\n\n## API\nCall methods om the api like so: `butler.users.methodName`. All methods return a promise, and you can access the data you're expecting to come back in: `.then(function(data) {...})`.\n\n### insert(data)\nInserts a record\n\n| Parameter | Type |\n| --- | --- |\n| data | object |\n\n```javascript\nbutler.users.insert({\n    name: \"Alfred Pennyworth\",\n    email: \"alfred@waynemanor.com\",\n    status: 1,\n    title: \"Butler\"\n}).then...\n```\n\n### getById\nGets a record by the 'id' value. Uses `getByUniqueField` internally, so if you need to use a different field, use that instead.\n\n| Parameter | Type |\n| --- | --- |\n| id | string or int |\n\n```javascript\nbutler.users.getById(3454).then...\n```\n\n### getByUniqueField\nGets a single record by a unique field. Using this on a non-unique field is not recommended and may give unexpected results.\n\n| Parameter | Type |\n| --- | --- |\n| field | string |\n| value | string |\n\n```javascript\nbutler.users.getByUniqueField(\"email\", \"alfred@waynemanor.com\").then...\n```\n\n### getAllByField\nGets all records with a single matching field.\n\n| Parameter | Type |\n| --- | --- |\n| field | string |\n| value | string |\n\n```javascript\nbutler.users.getByUniqueField(\"title\", \"Butler\").then...\n```\n\n### getWhere\nLike `getAllByField`, but you can include an object to match multiple fields, and will return all that match.\n\n| Parameter | Type |\n| --- | --- |\n| data | object |\n\n```javascript\nbutler.users.getWhere({\n    title: \"Butler\"\n}).then...\n```\n\n### getOneWhere\nLike `getWhere`, but will return a single result instead of an array.\n\n| Parameter | Type |\n| --- | --- |\n| data | object |\n\n```javascript\nbutler.users.getOneWhere({\n    title: \"Butler\",\n    status: 1\n}).then...\n```\n\n### getCountWhere\nGets the number of rows that match\n\n| Parameter | Type |\n| --- | --- |\n| data | object |\n\n```javascript\nbutler.users.getCountWhere({\n    title: \"Butler\",\n    status: 1\n}).then...\n```\n\n### updateWhere\nUpdates a record where, given a set of fields match\n\n| Parameter | Type | |\n| --- | --- | --- |\n| updatedFields | object | Fields to be updated |\n| whereFields | object | Fields to match |\n\n```javascript\nbutler.users.updateWhere(\n    { status: 2 },\n    { email: \"alfred@waynemanor.com\"} \n).then...\n```\n\n### deleteWhere\nDeletes a record where, given a set of fields match. If you don't pass in a valid object of fields to match, this function will return `Promise.resolve()` and will not delete anything. If you want to delete all the rows in the table use `deleteAll` instead.\n\n| Parameter | Type | |\n| --- | --- | --- |\n| whereFields | object | Fields to match |\n\n```javascript\nbutler.users.deleteWhere(\n    { email: \"alfred@waynemanor.com\" }\n).then...\n```\n\n### deleteAll\nDeletes all records in the table. Obviously, be careful with this one. :)\n\n```javascript\nbutler.user_logs.deleteAll().then...\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanfrancy%2Fmybutler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanfrancy%2Fmybutler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanfrancy%2Fmybutler/lists"}