{"id":16237967,"url":"https://github.com/codegoalie/mysql-cellophane","last_synced_at":"2025-04-08T08:48:54.133Z","repository":{"id":1225217,"uuid":"1153279","full_name":"codegoalie/mysql-cellophane","owner":"codegoalie","description":"very thin wrapper for mysql adapters","archived":false,"fork":false,"pushed_at":"2011-04-13T03:41:19.000Z","size":344,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T05:43:50.051Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codegoalie.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-12-09T14:14:59.000Z","updated_at":"2014-06-25T13:57:19.000Z","dependencies_parsed_at":"2022-08-16T12:40:07.094Z","dependency_job_id":null,"html_url":"https://github.com/codegoalie/mysql-cellophane","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/codegoalie%2Fmysql-cellophane","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codegoalie%2Fmysql-cellophane/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codegoalie%2Fmysql-cellophane/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codegoalie%2Fmysql-cellophane/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codegoalie","download_url":"https://codeload.github.com/codegoalie/mysql-cellophane/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809407,"owners_count":20999806,"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-10T13:38:07.187Z","updated_at":"2025-04-08T08:48:54.115Z","avatar_url":"https://github.com/codegoalie.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"MySQL-Cellphane\n==============\nA very thin wrapper for mysql adapters. Useful for people who are comfortable \nwith SQL, but are tired of the annoyances of writing each query each time. \nMySQL-Cellophane helps by abstracting away some of the repetative query \nbuilding process while allowing complete control over your queries.\n\nMySQL-Cellophane aims to fill the gap between hand typing each query and a \nfull ORM by streamlining the creation of db connections, setting smart defaults, \neasily running multiple, similar queries, returning intelligent responses, and \navoiding SQL injection.\n\nRequires the mysql gem \n\n    gem install mysql\n\n\u003e there is an old version mysql.rb included in public folder above or \n\u003e from http://www.tmtm.org/en/ruby/mysql/\n\nGetting Started\n---------------\n\n### Attributes\n\nbasic building blocks of queries\n\n- table\n\n  specifies the table to operate on\n\n- id_field\n\n  specifies which column in the main condition (used with id)\n\n  is set to 1 by default to override the main condition (id must be set to 1 as well)\n\n- id\n\n  specifies a value for the main condition (used with id_field)\n\n  is set to 1 by default to override the main condition (id_field must be set to 1 as well)\n\n  is escaped before being placed in query\n\n- extra_cond\n\n  concatinated onto the end of the base query\n  IS NOT ESCAPED - use esc method to escape values\n\n### Methods\n\nEach interaction method can optionally take a final hash argument. This hash can set any of \nthe class attributes listed above. See the examples below for more information.\n\n- select\n\n  performs a select query\n\n- insert({hash})\n\n  requires a hash argument of symbol keys for column names and values for each column \n  to be inserted\n- update\n\n  requires a hash argument of symbol keys for column names and values for each column \n  to be updated\n\n- delete\n  \n  performs a delete query\n\n------\n\n### Examples\n#### friends table\n\n\u003ctable border=1 \u003e\n  \u003cthead\u003e\n    \u003cth\u003eid\n    \u003cth\u003ename\u003c/th\u003e\n    \u003cth\u003eage\u003c/th\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e \n      \u003ctd\u003e1\n      \u003ctd\u003eChris\u003c/td\u003e\n      \u003ctd\u003e26\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eHayley\u003c/td\u003e\n      \u003ctd\u003e24\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eBobby\u003c/td\u003e\n      \u003ctd\u003e25\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n#### initialize\n\n    db = MySQLc.new {:user =\u003e 'mysql_user', :password =\u003e 'mysql_password', :database =\u003e 'database'}\n\n#### select\n\nget all rows\n\n    db.table = 'friends' \n    result = db.select # SELECT * FROM friends WHERE 1=1\n    result.fetch_hash #=\u003e { 'id' =\u003e 1, 'name' =\u003e 'Chris',  'age' =\u003e 26 }\n    result.fetch_hash #=\u003e { 'id' =\u003e 2, 'name' =\u003e 'Hayley', 'age' =\u003e 24 }\n    result.fetch_hash #=\u003e { 'id' =\u003e 3, 'name' =\u003e 'Bobby',  'age' =\u003e 25 }\n\nget one friend\n\n    db.id_field = 'id'\n    db.id       = 1\n    result = db.select # SELECT * FROM friends WHERE id = 1\n    result.fetch_hash #=\u003e { 'id' =\u003e 1, 'name' =\u003e 'Chris',  'age' =\u003e 26 }\n\nNotice how we don't need to specify the table again because we did in the example above. One of the very \nnice features of MySQL Cellophane is that it keeps your values for you. \n\nsetting the options in-line\n\n    result = db.select({ :table =\u003e 'friends', :id_field =\u003e 'id', :id =\u003e 2}) # SELECT * FROM friends WHERE id = 2\n    result.fetch_row #=\u003e [ 2, 'Hayley', 24 ]\n\nspecifying columns\n\n    db.field_list = 'name, age'\n    db.id = 1\n    db.id_field = 1\n    result = db.select # SELECT name, age FROM friends WHERE 1=1\n    result.fetch_row #=\u003e [ 'Chris', 26 ]\n    result.fetch_row #=\u003e [ 'Hayley', 24 ]\n\nusing extra_cond\n\n    db = MySQLc.new\n    db.table = 'friends'\n    db.field_list = 'name'\n    db.extra_cond = \"name LIKE '%y' ORDER BY name\"\n    result = db.select # SELECT * FROM friends WHERE 1=1 AND name LIKE '%y' ORDER BY name\n    result.fetch_row #=\u003e [ 'Bobby' ]\n    result.fetch_row #=\u003e [ 'Hayley' ]\n\n    \n#### insert\n\n    db.insert { :name =\u003e 'Katie', :age =\u003e 23 }\n\n##### new friends table\n\n\u003ctable border=1 \u003e\n  \u003cthead\u003e\n    \u003cth\u003eid\n    \u003cth\u003ename\u003c/th\u003e\n    \u003cth\u003eage\u003c/th\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e \n      \u003ctd\u003e1\n      \u003ctd\u003eChris\u003c/td\u003e\n      \u003ctd\u003e26\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eHayley\u003c/td\u003e\n      \u003ctd\u003e24\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eBobby\u003c/td\u003e\n      \u003ctd\u003e25\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eKatie\u003c/td\u003e\n      \u003ctd\u003e23\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\ninline\n\n    new_id = db.insert { :name =\u003e 'Jared', :age =\u003e 26 }, { :table =\u003e 'friends' }\n    new_id  #=\u003e 5\n\n##### new new friends table\n\n\u003ctable border=1 \u003e\n  \u003cthead\u003e\n    \u003cth\u003eid\n    \u003cth\u003ename\u003c/th\u003e\n    \u003cth\u003eage\u003c/th\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e \n      \u003ctd\u003e1\n      \u003ctd\u003eChris\u003c/td\u003e\n      \u003ctd\u003e26\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eHayley\u003c/td\u003e\n      \u003ctd\u003e24\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eBobby\u003c/td\u003e\n      \u003ctd\u003e25\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eKatie\u003c/td\u003e\n      \u003ctd\u003e23\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eJared\u003c/td\u003e\n      \u003ctd\u003e26\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n#### update\n\n    db.id_field = 'name'\n    db.id       = 'Katie'\n    db.update { :age =\u003e 22 }\n    db.select.fetch_hash #=\u003e { 'id' =\u003e 4, 'name' =\u003e 'Katie',  'age' =\u003e 22 }\n\n    db.update { :age =\u003e 27 }, { :id =\u003e 26, :id_field =\u003e 'age', :table =\u003e 'friends' }\n    db.id = 27\n    db.select.fetch_hash #=\u003e { 'id' =\u003e 1, 'name' =\u003e 'Chris',  'age' =\u003e 27 }\n    db.select.fetch_hash #=\u003e { 'id' =\u003e 5, 'name' =\u003e 'Jared',  'age' =\u003e 27 }\n\n#### delete\n\n    db = MySQLc.new\n    db.table = 'friends'\n    db.extra_cond = 'age \u003c 25'\n    db.delete\n\n\u003ctable border=1 \u003e\n  \u003cthead\u003e\n    \u003cth\u003eid\n    \u003cth\u003ename\u003c/th\u003e\n    \u003cth\u003eage\u003c/th\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e \n      \u003ctd\u003e1\n      \u003ctd\u003eChris\u003c/td\u003e\n      \u003ctd\u003e26\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eBobby\u003c/td\u003e\n      \u003ctd\u003e25\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eJared\u003c/td\u003e\n      \u003ctd\u003e26\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodegoalie%2Fmysql-cellophane","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodegoalie%2Fmysql-cellophane","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodegoalie%2Fmysql-cellophane/lists"}