{"id":16445094,"url":"https://github.com/jaymon/mingo","last_synced_at":"2025-10-27T05:31:37.564Z","repository":{"id":66175163,"uuid":"376475","full_name":"Jaymon/Mingo","owner":"Jaymon","description":"Mingo is an easy to use key/value ORM for PHP that can use PostgreSQL, MySql, or SQLite as its backend","archived":false,"fork":false,"pushed_at":"2013-03-16T22:46:57.000Z","size":760,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-01T02:41:26.494Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","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/Jaymon.png","metadata":{"files":{"readme":"README.md","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":"2009-11-17T22:02:27.000Z","updated_at":"2023-11-16T19:12:07.000Z","dependencies_parsed_at":"2023-02-19T23:40:18.215Z","dependency_job_id":null,"html_url":"https://github.com/Jaymon/Mingo","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/Jaymon%2FMingo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaymon%2FMingo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaymon%2FMingo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaymon%2FMingo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jaymon","download_url":"https://codeload.github.com/Jaymon/Mingo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238445844,"owners_count":19473822,"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-11T09:43:11.972Z","updated_at":"2025-10-27T05:31:37.239Z","avatar_url":"https://github.com/Jaymon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# What is Mingo?\n\nMingo is an easy to use database abstraction layer that uses the db as a schema-less document \nstorage engine based on [how Friendfeed used MySql](http://bret.appspot.com/entry/how-friendfeed-uses-mysql).\n\nCurrently, by default, Mingo can use MySQL, SQLite, or PostgreSQL databases as the backend. \nI've updated the code quite a bit so I've disabled the __Mongo__, __Lucene__, and __Postgres Hstore__ \ninterfaces until I can refactor and update them. \n\nYou can add any other databases easily by extending `MingoInterface` and implementing all the required methods.\n\n# Using Mingo\n\nUsing Mingo is as easy as creating a new class that extends MingoOrm. For our example we'll create a User class:\n\n    class User extends MingoOrm {\n\n      /*\n       *  every child that extends MingoOrm needs to implement this method\n       */\n      protected function populateTable(MingoTable $table){\n        \n        // we don't have to define all the fields, but it helps with indexes\n        \n        // the username is a string of 0, 32 characters\n        $field = new MingoField('username', MingoField::TYPE_STR, array(0, 32));\n        \n        // the password is a hash of 32 characters\n        $field = new MingoField('password', MingoField::TYPE_STR, 32);\n        \n        // now set an index, the index name is \"un_and_pw\" and it uses the username, and password fields\n        $table-\u003esetIndex('un_and_pw', array('username', 'password'));\n      \n      }//method\n\n    }//class\n\nthat's all the setup you really need to do, pretty much everything else is handled by Mingo, \nincluding table and index creation.\n\nLet's see our new `User` object in action, first we need to connect to our interface.\n\nTo use `SQLite`:\n\n    $config = new MingoConfig();\n    $config-\u003esetName('/path/to/db.sqlite'); //db name    \n    $db = new MingoSQLiteInterface();\n\nTo use `MySQL`:\n\n    $config = new MingoConfig();\n    $config-\u003esetName('db'); //db name\n    $config-\u003esetHost('localhost'); // db host\n    $config-\u003esetUsername('username');\n    $config-\u003esetPassword('****');    \n    $db = new MingoMySQLInterface();\n    \nTo use `PostgreSQL`:\n\n    $config = new MingoConfig();\n    $config-\u003esetName('db'); //db name\n    $config-\u003esetHost('localhost'); // db host\n    $config-\u003esetUsername('username');\n    $config-\u003esetPassword('****');\n    $db = new MingoPostgreSQLInterface();\n    \nAfter we have set our connection we need to connect:\n    \n    $config-\u003esetDebug(true); // better debugging/logging for test, set to false for production code\n    \n    $db-\u003econnect($config);\n\nNow, we can create a `User` and save it into the db:\n\n    $user = new User();\n    $user-\u003esetDb($db);\n    \n    $user-\u003esetUsername('tester');\n    $user-\u003esetPassword(md5('1234'));\n    \n    // we can set any other fields we want even if we've never defined them\n    $user-\u003esetFancyName('Magic Unicorn');\n    $user-\u003esetEmail('magic@unicorn.com');\n    \n    // save the user into the db\n    $user-\u003eset();\n\nand that's that, the `User` is now saved (notice we didn't have to do anything crazy \nlike create a table. Mingo handles all that for us). To make sure, let's load him up into a \nnew `user` instance:\n\n    // query objects allow us to query a specified table\n    $query = new MingoQuery('User',$db);\n    \n    // the query object get() method returns an iterator object with the requested results\n    $user_iterator = $query-\u003eget();\n\n    foreach($user_iterator as $user){\n      echo $user-\u003egetFancyName(),PHP_EOL;\n      echo '  ',$user-\u003egetUsername(),' - ',$user-\u003egetPassword(),PHP_EOL;\n    }//foreach\n\nthis is just a basic example but it shows you how easy Mingo is to use. each class extended \nfrom `MingoOrm` has many built in magic functions to make doing things easy. You just saw \nthe `set*()` and `get*()` magic functions, but you also have `has*()` magic functions to make \nsure a field exists and is non-empty (eg, `$user-\u003ehasPassword()` to see if the password field \nexists and is non-empty). The `exists*()` to just see if a field exists (it could be empty). \nThe `kill*()` functions to remove a field. The `bump*()` functions to increment the field by count \n(eg, `$user-\u003ebumpView(1)`). And `is*()` functions to see if a field contains a value \n(eg, `$user-\u003eisUsername('tester')`). You can also reach into arrays with all the methods:\n\n    $user = new User();\n    $user-\u003esetField('attributes',array('foo' =\u003e 1,'bar' =\u003e 2));\n    $user-\u003egetField(array('attributes','foo')); // 1\n    $user-\u003eisField(array('attributes','foo'),1); // true\n\n\nTo query, you can use a `MingoQuery` class instance to make getting results from the db painless. \nFor example, to get all users with certain usernames, you could:\n\n    $query = new MingoQuery('User',$db);\n    $user_iterator = $query-\u003einUsername('tester','john','paul','homer','bart')-\u003eget();\n    echo 'loaded this many users: ',count($user_iterator),PHP_EOL;\n\nAnd, if you wanted to sort them in alphabetical order, you can do that too:\n\n    $user_iterator = $query-\u003einUsername('tester','john','paul','homer','bart')-\u003eascUsername()-\u003eget();\n\nWhat about reverse alphabetical order:\n\n    $user_iterator = $query-\u003einUsername('tester','john','paul','homer','bart')-\u003edescUsername()-\u003eget();\n\n# Installing Mingo\n\nMingo requires php \u003e=5.3, but if you have to use Mingo in something like 5.2, you can if you don't\nuse the MingoOrm::createQuery() method, though this will change in the future as the code becomes\nnamespaced and uses more 5.3+ features.\n\nIf you have `PHPUnit` installed then you should be able to run the unit tests found in the `test/phpunit` \nfolder (though you may have to edit the connection variables in any of the interface tests to use your \nversions of whatever db you want to use).\n\nThe code should run on both Windows and Linux without problems.\n\n# Using Mingo to develop\n\nMingo tries to recover if a given table isn't found by trying to create the table on the fly \nand creating any new indexes. Usually, it will only have to recover from not having a table once, \nthis makes it really easy to deploy new `MingoOrm` classes since tables will be automatically \ngenerated the first time Mingo can't find them (kind of like an automatic install script). \nThis allows you to push to production and not have to worry about running an install script or \nanything for many cases and gives you the flexibility of creating an install script only when \nyou need to do special things.\n\n# Other\n\n## Mingo in the press:\n\n[Techcrunch Jan, 12, 2010](http://www.techcrunch.com/2010/01/12/plancast-facebook-events/)\n\"[Plancast](http://plancast.com) has started using a 'No SQL' solution for some of their data. More tech-savvy readers may \nrecognize that is also a solution FriendFeed is using on their backend, as Facebook's Bret Taylor wrote \nabout at length [here](http://bret.appspot.com/entry/how-friendfeed-uses-mysql). \nPlancast has [open-sourced](http://github.com/Jaymon/Mingo) their version of this.\"\n\n## License\n\n[The MIT License](http://www.opensource.org/licenses/mit-license.php)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaymon%2Fmingo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaymon%2Fmingo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaymon%2Fmingo/lists"}