增加docke部署
This commit is contained in:
115
codes/agent/game-docker/api/lib/phprs/ezsql/rules/basic.php
Normal file
115
codes/agent/game-docker/api/lib/phprs/ezsql/rules/basic.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: basic.php 131 2015-10-10 02:25:57Z yangmin.cao $
|
||||
* @author caoym(caoyangmin@gmail.com)
|
||||
*/
|
||||
namespace phprs\ezsql\rules\basic;
|
||||
|
||||
use phprs\ezsql\impls\ExecImpl;
|
||||
use phprs\ezsql\impls\LimitImpl;
|
||||
use phprs\ezsql\impls\OrderByImpl;
|
||||
use phprs\ezsql\impls\WhereImpl;
|
||||
require_once dirname(__DIR__).'/impls.php';
|
||||
|
||||
class BasicRule
|
||||
{
|
||||
public function __construct($context){
|
||||
$this->context = $context;
|
||||
}
|
||||
protected $context;
|
||||
}
|
||||
|
||||
class ExecRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* Execute sql
|
||||
* @param \PDO $db
|
||||
* @param boolean $errExce whether throw exceptios
|
||||
* @return Response
|
||||
*/
|
||||
public function exec($db, $errExce=true) {
|
||||
return ExecImpl::exec($this->context, $db, $errExce);
|
||||
}
|
||||
}
|
||||
|
||||
class LimitRule extends ExecRule
|
||||
{
|
||||
/**
|
||||
* limit(1) => "LIMIT 1"
|
||||
* @param int $size
|
||||
* @return \phprs\ezsql\rules\basic\ExecRule
|
||||
*/
|
||||
public function limit($size) {
|
||||
LimitImpl::limit($this->context, $size);
|
||||
return new ExecRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
class OrderByRule extends LimitRule
|
||||
{
|
||||
public function __construct($context){
|
||||
parent::__construct($context);
|
||||
$this->impl = new OrderByImpl();
|
||||
}
|
||||
/**
|
||||
* orderByArgs(['column0', 'column1'=>Sql::$ORDER_BY_ASC]) => "ORDER BY column0,column1 ASC"
|
||||
* @param array $orders
|
||||
* @return \phprs\ezsql\rules\basic\LimitRule
|
||||
*/
|
||||
public function orderByArgs($orders) {
|
||||
$this->impl->orderByArgs($this->context, $orders);
|
||||
return new LimitRule($this->context);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* orderBy('column') => "ORDER BY column"
|
||||
* orderBy('column', Sql::$ORDER_BY_ASC) => "ORDER BY column ASC"
|
||||
* orderBy('column0')->orderBy('column1') => "ORDER BY column0, column1"
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $order Sql::$ORDER_BY_ASC or Sql::$ORDER_BY_DESC
|
||||
*
|
||||
* @return \phprs\ezsql\rules\basic\LimitRule
|
||||
*/
|
||||
public function orderBy($column, $order=null) {
|
||||
$this->impl->orderBy($this->context, $column, $order);
|
||||
return new LimitRule($this->context);
|
||||
}
|
||||
private $impl;
|
||||
}
|
||||
|
||||
class WhereRule extends OrderByRule
|
||||
{
|
||||
/**
|
||||
*
|
||||
* where('a=?', 1) => "WHERE a=1"
|
||||
* where('a=?', Sql::native('now()')) => "WHERE a=now()"
|
||||
* where('a IN (?)', [1, 2]) => "WHERE a IN (1,2)"
|
||||
*
|
||||
* @param string $expr
|
||||
* @param mixed $_
|
||||
* @return \phprs\ezsql\rules\basic\OrderByRule
|
||||
*/
|
||||
public function where($expr, $_= null) {
|
||||
WhereImpl::where($this->context, $expr, array_slice(func_get_args(), 1));
|
||||
return new OrderByRule($this->context);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* whereArgs([
|
||||
* 'a'=>1,
|
||||
* 'b'=>['IN'=>[1,2]]
|
||||
* 'c'=>['BETWEEN'=>[1,2]]
|
||||
* 'd'=>['<>'=>1]
|
||||
* ])
|
||||
*
|
||||
* =>
|
||||
* "WHERE a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
|
||||
* @param string $args
|
||||
* @return \phprs\ezsql\rules\basic\OrderByRule
|
||||
*/
|
||||
public function whereArgs($args) {
|
||||
WhereImpl::whereArgs($this->context, $args);
|
||||
return new OrderByRule($this->context);
|
||||
}
|
||||
}
|
||||
25
codes/agent/game-docker/api/lib/phprs/ezsql/rules/delete.php
Normal file
25
codes/agent/game-docker/api/lib/phprs/ezsql/rules/delete.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: delete.php 131 2015-10-10 02:25:57Z yangmin.cao $
|
||||
* @author caoym(caoyangmin@gmail.com)
|
||||
*/
|
||||
namespace phprs\ezsql\rules\delete;
|
||||
use phprs\ezsql\rules\basic\BasicRule;
|
||||
use phprs\ezsql\impls\DeleteImpl;
|
||||
use phprs\ezsql\rules\basic\WhereRule;
|
||||
|
||||
require_once dirname(__DIR__).'/impls.php';
|
||||
require_once __DIR__.'/basic.php';
|
||||
|
||||
class DeleteRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* deleteFrom('table') => "DELETE FROM table"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\basic\WhereRule
|
||||
*/
|
||||
public function deleteFrom($table) {
|
||||
DeleteImpl::deleteFrom($this->context, $table);
|
||||
return new WhereRule($this->context);
|
||||
}
|
||||
}
|
||||
42
codes/agent/game-docker/api/lib/phprs/ezsql/rules/insert.php
Normal file
42
codes/agent/game-docker/api/lib/phprs/ezsql/rules/insert.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: insert.php 131 2015-10-10 02:25:57Z yangmin.cao $
|
||||
* @author caoym(caoyangmin@gmail.com)
|
||||
*/
|
||||
namespace phprs\ezsql\rules\insert;
|
||||
|
||||
use phprs\ezsql\rules\basic\BasicRule;
|
||||
use phprs\ezsql\rules\basic\ExecRule;
|
||||
use phprs\ezsql\impls\InsertImpl;
|
||||
use phprs\ezsql\impls\ValuesImpl;
|
||||
|
||||
require_once dirname(__DIR__).'/impls.php';
|
||||
require_once __DIR__.'/basic.php';
|
||||
|
||||
class InsertRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
*
|
||||
* insertInto('table')->values([1,2]) => "INSERT INTO table VALUES(1,2)"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\insert\ValuesRule
|
||||
*/
|
||||
public function insertInto($table) {
|
||||
InsertImpl::insertInto($this->context, $table);
|
||||
return new ValuesRule($this->context);
|
||||
}
|
||||
}
|
||||
class ValuesRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
*
|
||||
* insertInto('table')->values([1,2]) => "INSERT INTO table VALUES(1,2)"
|
||||
* insertInto('table')->values(['a'=>1, 'b'=>Sql::native('now()')]) => "INSERT INTO table(a,b) VALUES(1,now())"
|
||||
* @param unknown $values
|
||||
* @return \phprs\ezsql\rules\basic\ExecRule
|
||||
*/
|
||||
public function values($values) {
|
||||
ValuesImpl::values($this->context, $values);
|
||||
return new ExecRule($this->context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace phprs\ezsql\rules\replace;
|
||||
|
||||
use phprs\ezsql\rules\basic\BasicRule;
|
||||
use phprs\ezsql\rules\basic\ExecRule;
|
||||
use phprs\ezsql\impls\ReplaceImpl;
|
||||
use phprs\ezsql\impls\ValuesImpl;
|
||||
|
||||
require_once dirname(__DIR__).'/impls.php';
|
||||
require_once __DIR__.'/basic.php';
|
||||
|
||||
class ReplaceIntoRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* replaceInto('table')->values([1,2]) => "REPLACE INTO table VALUES(1,2)"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\replace\ValuesRule
|
||||
*/
|
||||
public function replaceInto($table) {
|
||||
ReplaceImpl::replaceInto($this->context, $table);
|
||||
return new ValuesRule($this->context);
|
||||
}
|
||||
}
|
||||
class ValuesRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* replaceInto('table')->values([1,2]) => "REPLACE INTO table VALUES(1,2)"
|
||||
* replaceInto('table')->values(['a'=>1, 'b'=>Sql::native('now()')]) => "REPLACE INTO table(a,b) VALUES(1,now())"
|
||||
* @param unknown $values
|
||||
* @return \phprs\ezsql\rules\basic\ExecRule
|
||||
*/
|
||||
public function values($values) {
|
||||
ValuesImpl::values($this->context, $values);
|
||||
return new ExecRule($this->context);
|
||||
}
|
||||
}
|
||||
271
codes/agent/game-docker/api/lib/phprs/ezsql/rules/select.php
Normal file
271
codes/agent/game-docker/api/lib/phprs/ezsql/rules/select.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: select.php 246 2015-10-21 04:48:09Z yangmin.cao $
|
||||
* @author caoym(caoyangmin@gmail.com)
|
||||
*/
|
||||
namespace phprs\ezsql\rules\select;
|
||||
use phprs\ezsql\rules\basic\BasicRule;
|
||||
use phprs\ezsql\impls\ExecImpl;
|
||||
use phprs\ezsql\impls\SelectImpl;
|
||||
use phprs\ezsql\impls\FromImpl;
|
||||
use phprs\ezsql\impls\JoinImpl;
|
||||
use phprs\ezsql\impls\JoinOnImpl;
|
||||
use phprs\ezsql\impls\WhereImpl;
|
||||
use phprs\ezsql\impls\GroupByImpl;
|
||||
use phprs\ezsql\impls\OrderByImpl;
|
||||
use phprs\ezsql\impls\LimitImpl;
|
||||
use phprs\ezsql\impls\ForUpdateOfImpl;
|
||||
use phprs\ezsql\impls\ForUpdateImpl;
|
||||
|
||||
require_once dirname(__DIR__).'/impls.php';
|
||||
require_once __DIR__.'/basic.php';
|
||||
|
||||
class SelectRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* select('column0, column1') => "SELECT column0, column1"
|
||||
* select('column0', 'column1') => "SELECT column0, column1"
|
||||
* @param string $columns
|
||||
* @return \phprs\ezsql\rules\select\FromRule
|
||||
*/
|
||||
public function select($columns) {
|
||||
SelectImpl::select($this->context, $columns);
|
||||
return new FromRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
class GetRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* Execute sql and get responses
|
||||
* @param \PDO $db
|
||||
* @param $errExce whether throw exceptions
|
||||
* @return array
|
||||
*/
|
||||
public function get($db, $asDict=false,$errExce=true) {
|
||||
return ExecImpl::get($this->context, $db, $asDict,$errExce);
|
||||
}
|
||||
}
|
||||
class FromRule extends GetRule
|
||||
{
|
||||
/**
|
||||
* from('table') => "FROM table"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\select\JoinRule
|
||||
*/
|
||||
public function from($table){
|
||||
FromImpl::from($this->context, $table);
|
||||
return new JoinRule($this->context);
|
||||
}
|
||||
}
|
||||
class ForUpdateOfRule extends GetRule
|
||||
{
|
||||
/**
|
||||
* forUpdate()->of('column') => 'FOR UPDATE OF column'
|
||||
* @param string $column
|
||||
* @return \phprs\ezsql\rules\select\GetRule
|
||||
*/
|
||||
public function of($column){
|
||||
ForUpdateOfImpl::of($this->context, $column);
|
||||
return new GetRule($this->context);
|
||||
}
|
||||
}
|
||||
class ForUpdateRule extends GetRule
|
||||
{
|
||||
/**
|
||||
* forUpdate() => 'FOR UPDATE'
|
||||
* @return \phprs\ezsql\rules\select\ForUpdateOfRule
|
||||
*/
|
||||
public function forUpdate(){
|
||||
ForUpdateImpl::forUpdate($this->context);
|
||||
return new ForUpdateOfRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
class LimitRule extends ForUpdateRule
|
||||
{
|
||||
/**
|
||||
* limit(0,1) => "LIMIT 0,1"
|
||||
* @param int $start
|
||||
* @param int $size
|
||||
* @return \phprs\ezsql\rules\select\ForUpdateRule
|
||||
*/
|
||||
public function limit($start, $size) {
|
||||
LimitImpl::limitWithOffset($this->context, $start, $size);
|
||||
return new ForUpdateRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
class OrderByRule extends LimitRule
|
||||
{
|
||||
public function __construct($context){
|
||||
parent::__construct($context);
|
||||
$this->order = new OrderByImpl();
|
||||
}
|
||||
/**
|
||||
* orderBy('column') => "ORDER BY column"
|
||||
* orderBy('column', Sql::$ORDER_BY_ASC) => "ORDER BY column ASC"
|
||||
* orderBy('column0')->orderBy('column1') => "ORDER BY column0, column1"
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $order Sql::$ORDER_BY_ASC or Sql::$ORDER_BY_DESC
|
||||
* @return \phprs\ezsql\rules\select\OrderByRule
|
||||
*/
|
||||
public function orderBy($column, $order=null) {
|
||||
$this->order->orderBy($this->context, $column, $order);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* orderByArgs(['column0', 'column1'=>Sql::$ORDER_BY_ASC]) => "ORDER BY column0,column1 ASC"
|
||||
* @param array $args
|
||||
* @return \phprs\ezsql\rules\select\OrderByRule
|
||||
*/
|
||||
public function orderByArgs($args) {
|
||||
$this->order->orderByArgs($this->context, $args);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var OrderByImpl
|
||||
*/
|
||||
private $order;
|
||||
}
|
||||
|
||||
class HavingRule extends OrderByRule
|
||||
{
|
||||
/**
|
||||
*
|
||||
* having('SUM(a)=?', 1) => "HAVING SUM(a)=1"
|
||||
* having('a>?', Sql::native('now()')) => "HAVING a>now()"
|
||||
* having('a IN (?)', [1, 2]) => "HAVING a IN (1,2)"
|
||||
*
|
||||
* @param string $expr
|
||||
* @param string $_
|
||||
* @return \phprs\ezsql\rules\select\OrderByRule
|
||||
*/
|
||||
public function having($expr, $_=null) {
|
||||
WhereImpl::having($this->context, $expr, array_slice(func_get_args(), 1));
|
||||
return new OrderByRule($this->context);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* havingArgs([
|
||||
* 'a'=>1,
|
||||
* 'b'=>['IN'=>[1,2]]
|
||||
* 'c'=>['BETWEEN'=>[1,2]]
|
||||
* 'd'=>['<>'=>1]
|
||||
* ])
|
||||
*
|
||||
* =>
|
||||
* "HAVING a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
|
||||
*
|
||||
*
|
||||
* @param array $args
|
||||
* @return \phprs\ezsql\rules\select\OrderByRule
|
||||
*/
|
||||
public function havingArgs($args) {
|
||||
WhereImpl::havingArgs($this->context, $args);
|
||||
return new OrderByRule($this->context);
|
||||
}
|
||||
}
|
||||
class GroupByRule extends OrderByRule
|
||||
{
|
||||
/**
|
||||
* groupBy('column') => "GROUP BY column"
|
||||
* @param string $column
|
||||
* @return \phprs\ezsql\rules\select\HavingRule
|
||||
*/
|
||||
public function groupBy($column) {
|
||||
GroupByImpl::groupBy($this->context, $column);
|
||||
return new HavingRule($this->context);
|
||||
}
|
||||
}
|
||||
class WhereRule extends GroupByRule
|
||||
{
|
||||
/**
|
||||
*
|
||||
* where('a=?', 1) => "WHERE a=1"
|
||||
* where('a=?', Sql::native('now()')) => "WHERE a=now()"
|
||||
* where('a IN (?)', [1, 2]) => "WHERE a IN (1,2)"
|
||||
*
|
||||
* @param string $expr
|
||||
* @param mixed $_
|
||||
* @return \phprs\ezsql\rules\select\GroupByRule
|
||||
*/
|
||||
public function where($expr, $_=null) {
|
||||
WhereImpl::where($this->context, $expr, array_slice(func_get_args(), 1));
|
||||
return new GroupByRule($this->context);
|
||||
}
|
||||
/**
|
||||
* whereArgs([
|
||||
* 'a'=>1,
|
||||
* 'b'=>['IN'=>[1,2]]
|
||||
* 'c'=>['BETWEEN'=>[1,2]]
|
||||
* 'd'=>['<>'=>1]
|
||||
* ])
|
||||
*
|
||||
* =>
|
||||
* "WHERE a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
|
||||
* @param array $args
|
||||
* @return\phprs\ezsql\rules\select\GroupByRule
|
||||
*/
|
||||
public function whereArgs($args) {
|
||||
WhereImpl::whereArgs($this->context,$args);
|
||||
return new GroupByRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
class JoinRule extends WhereRule
|
||||
{
|
||||
/**
|
||||
* join('table1')->on('table0.id=table1.id') => "JOIN table1 ON table0.id=table1.id"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\select\JoinOnRule
|
||||
*/
|
||||
public function join($table){
|
||||
JoinImpl::join($this->context,null, $table);
|
||||
return new JoinOnRule($this->context);
|
||||
}
|
||||
/**
|
||||
* leftJoin('table1')->on('table0.id=table1.id') => "LEFT JOIN table1 ON table0.id=table1.id"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\select\JoinOnRule
|
||||
*/
|
||||
public function leftJoin($table){
|
||||
JoinImpl::join($this->context,'LEFT', $table);
|
||||
return new JoinOnRule($this->context);
|
||||
}
|
||||
/**
|
||||
* rightJoin('table1')->on('table0.id=table1.id') => "RIGHT JOIN table1 ON table0.id=table1.id"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\select\JoinOnRule
|
||||
*/
|
||||
public function rightJoin($table) {
|
||||
JoinImpl::join($this->context,'RIGHT', $table);
|
||||
return new JoinOnRule($this->context);
|
||||
}
|
||||
/**
|
||||
* innerJoin('table1')->on('table0.id=table1.id') => "INNER JOIN table1 ON table0.id=table1.id"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\select\JoinOnRule
|
||||
*/
|
||||
public function innerJoin($table) {
|
||||
JoinImpl::join($this->context,'INNER', $table);
|
||||
return new JoinOnRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
class JoinOnRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* join('table1')->on('table0.id=table1.id') => "JOIN table1 ON table0.id=table1.id"
|
||||
* @param string $condition
|
||||
* @return \phprs\ezsql\rules\select\WhereRule
|
||||
*/
|
||||
public function on($condition){
|
||||
JoinOnImpl::on($this->context, $condition);
|
||||
return new JoinRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
59
codes/agent/game-docker/api/lib/phprs/ezsql/rules/update.php
Normal file
59
codes/agent/game-docker/api/lib/phprs/ezsql/rules/update.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: update.php 131 2015-10-10 02:25:57Z yangmin.cao $
|
||||
* @author caoym(caoyangmin@gmail.com)
|
||||
*/
|
||||
namespace phprs\ezsql\rules\update;
|
||||
use phprs\ezsql\rules\basic\BasicRule;
|
||||
use phprs\ezsql\rules\basic\WhereRule;
|
||||
use phprs\ezsql\impls\UpdateSetImpl;
|
||||
use phprs\ezsql\impls\UpdateImpl;
|
||||
|
||||
|
||||
require_once dirname(__DIR__).'/impls.php';
|
||||
require_once __DIR__.'/basic.php';
|
||||
|
||||
class UpdateRule extends BasicRule
|
||||
{
|
||||
/**
|
||||
* update('table')->set('a', 1) => "UPDATE table SET a=1"
|
||||
* @param string $table
|
||||
* @return \phprs\ezsql\rules\update\UpdateSetRule
|
||||
*/
|
||||
public function update($table) {
|
||||
UpdateImpl::update($this->context, $table);
|
||||
return new UpdateSetRule($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateSetRule extends WhereRule
|
||||
{
|
||||
public function __construct($context){
|
||||
parent::__construct($context);
|
||||
$this->impl = new UpdateSetImpl();
|
||||
}
|
||||
/**
|
||||
* update('table')->set('a', 1) => "UPDATE table SET a=1"
|
||||
* update('table')->set('a', 1)->set('b',Sql::native('now()')) => "UPDATE table SET a=1,b=now()"
|
||||
* @param string $column
|
||||
* @param mixed $value
|
||||
* @return \phprs\ezsql\rules\update\UpdateSetRule
|
||||
*/
|
||||
public function set($column, $value) {
|
||||
$this->impl->set($this->context, $column, $value);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* update('table')->set(['a'=>1, 'b'=>Sql::native('now()')]) => "UPDATE table SET a=1,b=now()"
|
||||
* @param array $values
|
||||
* @return \phprs\ezsql\rules\update\UpdateSetRule
|
||||
*/
|
||||
public function setArgs($values) {
|
||||
$this->impl->setArgs($this->context, $values);
|
||||
return $this;
|
||||
}
|
||||
private $impl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user