{"id":19808314,"url":"https://github.com/maghead/magsql","last_synced_at":"2025-05-01T07:32:20.444Z","repository":{"id":62522443,"uuid":"91717096","full_name":"maghead/magsql","owner":"maghead","description":"high performance cross platform sql generator","archived":false,"fork":false,"pushed_at":"2018-01-11T14:15:40.000Z","size":1578,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T11:11:15.684Z","etag":null,"topics":["sql","universal"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maghead.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","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":"2017-05-18T16:49:48.000Z","updated_at":"2019-12-27T20:32:39.000Z","dependencies_parsed_at":"2022-11-02T14:46:18.350Z","dependency_job_id":null,"html_url":"https://github.com/maghead/magsql","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/maghead%2Fmagsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maghead%2Fmagsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maghead%2Fmagsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maghead%2Fmagsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maghead","download_url":"https://codeload.github.com/maghead/magsql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251840418,"owners_count":21652352,"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":["sql","universal"],"created_at":"2024-11-12T09:13:32.334Z","updated_at":"2025-05-01T07:32:20.065Z","avatar_url":"https://github.com/maghead.png","language":"PHP","readme":"# Magsql - the powerful sql builder designed for PHP7\n\n[![Build Status](https://travis-ci.org/maghead/magsql.svg?branch=master)](http://travis-ci.org/maghead/magsql)\n[![Coverage Status](https://img.shields.io/coveralls/maghead/magsql.svg)](https://coveralls.io/r/maghead/magsql)\n[![Latest Stable Version](https://poser.pugx.org/corneltek/sqlbuilder/v/stable.svg)](https://packagist.org/packages/corneltek/sqlbuilder) \n[![Total Downloads](https://poser.pugx.org/corneltek/sqlbuilder/downloads.svg)](https://packagist.org/packages/corneltek/sqlbuilder) \n[![Monthly Downloads](https://poser.pugx.org/corneltek/sqlbuilder/d/monthly)](https://packagist.org/packages/corneltek/sqlbuilder)\n[![Latest Unstable Version](https://poser.pugx.org/corneltek/sqlbuilder/v/unstable.svg)](https://packagist.org/packages/corneltek/sqlbuilder) \n[![License](https://poser.pugx.org/corneltek/sqlbuilder/license.svg)](https://packagist.org/packages/corneltek/sqlbuilder)\n\nIf you're looking for something that is not an ORM but can generate SQL for\nyou, you just found the right one.\n\nMagsql is not an ORM (Object relational mapping) system, but a toolset that helps you generate \ncross-platform SQL queries in PHP.\n\nMagsql is a stand-alone library, you can simply install it through composer\nor just require them (the class files) with your autoloader, and it has no\ndependencies.\n\n## Features\n\n* Simple API, easy to remember.\n* Fast \u0026 Powerful.\n* Custom parameter marker support:\n  * Question-mark parameter marker.\n  * Named parameter marker.\n* Configurable quote handler.\n* Zero dependency.\n\n## Synopsis\n\nHere is a short example of using Universal SelectQuery\n\n```php\nuse Magsql\\Universal\\Query\\SelectQuery;\nuse Magsql\\Driver\\MySQLDriver;\nuse Magsql\\Driver\\PgSQLDriver;\nuse Magsql\\Driver\\SQLiteDriver;\n\n$mysql = new MySQLDriver;\n$args = new ArgumentArray;\n\n$query = new SelectQuery;\n$query-\u003eselect(array('id', 'name', 'phone', 'address','confirmed'))\n    -\u003efrom('users', 'u')\n    -\u003epartitions('u1', 'u2', 'u3')\n    -\u003ewhere()\n        -\u003eis('confirmed', true)\n        -\u003ein('id', [1,2,3])\n    ;\n$query\n    -\u003ejoin('posts')\n        -\u003eas('p')\n        -\u003eon('p.user_id = u.id')\n    ;\n$query\n    -\u003eorderBy('rand()')\n    -\u003eorderBy('id', 'DESC')\n    ;\n\n$sql = $query-\u003etoSql($mysql, $args);\n\nvar_dump($sql);\nvar_dump($args);\n```\n\n\n## A More Detailed Description\n\nUnlike other SQL utilities, Magsql let you define the quote style and the\nparameter marker type. there are 2 parameter marker type you can choose:\n\n1. Question mark parameter marker (`?`)\n2. Named parameter. (`:id`, `:name`, `:address`, `:p1`)\n\nThe above two are supported by PDO directly, and the first one is also\nsupported by `mysqli`, `pgsql` extension.\n\nThe API is *dead simple, easy to remember*, you can just define one query, then pass\ndifferent query driver to the query object to get a different SQL string for\nyour targettting platform.\n\nIt also supports cross-platform query generation, there are three types of\nquery (currently): **Universal**, **MySQL**, **PgSQL**.  The **Universal** queries are\ncross-platform, you can use them to create a cross-platform PHP API of \nyour database system, and the supported platforms are: **MySQL**, **PgSQL** and **SQLite**.\n\nUniversql Queries:\n\n- CreateDatabaseQuery\n- DropDatabaseQuery\n- SelectQuery\n- InsertQuery\n- UpdateQuery\n- DeleteQuery\n- UnionQuery\n- CreateIndexQuery\n- DropIndexQuery\n\nTo see the implementation details, you can check the source code inside **Universal** namespace:\n\u003chttps://github.com/maghead/magsql/tree/master/Magsql/Universal/Query\u003e\n\nMySQL Queries:\n\n- CreateUserQuery\n- DropUserQuery\n- GrantQuery\n- SetPasswordQuery\n\nFor MySQL platform, the implementation is according to the specification of MySQL 5.6.\n\nFor PostgreSQL platform, the implementation is according to the specification of PostgreSQL 9.2.\n\n\n## Installation\n\n### Install through Composer\n\n    composer require corneltek/sqlbuilder\n\n## Getting Started\n\n[Documentation](https://github.com/maghead/magsql/wiki)\n\n## Development\n\n```\ncomposer install\n```\n\nCopy the `phpunit.xml` file for your local configuration:\n\n```sh\nphpunit -c your-phpunit.xml tests\n```\n\n## Contribution\n\nTo test with mysql database:\n\n    mysql -uroot -p\n    CREATE DATABASE sqlbuilder CHARSET utf8;\n    GRANT ALL PRIVILEGES ON sqlbuilder.* TO 'testing'@'localhost' identified by '';\n\n    --- or use this to remove password for testing account\n    SET PASSWORD FOR testing@localhost=PASSWORD('');\n\nTo test with pgsql database:\n\n    sudo -u postgres createdb sqlbuilder\n\n## Reference\n\n- http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html\n- http://www.postgresql.org/docs/8.2/static/sql-syntax.html\n- http://www.sqlite.org/optoverview.html\n\n## Author\n\nYo-An Lin (c9s) \u003ccornelius.howl@gmail.com\u003e\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaghead%2Fmagsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaghead%2Fmagsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaghead%2Fmagsql/lists"}