Yonna是一个极其纯净的纯API-PHP框架.
database库是yonna最强大的DB-ORM
Yonna demo:GOTO yonna
连贯写法,全解耦,autoload后随意使用
DB自带各种分析优化,所以不再需要 Model层进行优化,可专心编写你的service(scope)
DB::connect() // 默认 'default'
->table('system_data')
->field('key,value')
->in('key', $key)
->one();
DB::connect('mysql')
->table('system_data')
->field('key,value')
->in('key', $key)
->one();
DB::connect('pgsql')
->schemas('default')
->table('system_data')
->field('key,value')
->in('key', $key)
->multi();
DB::connect('mssql')
->schemas('default')
->table('system_data')
->field('key,value')
->in('key', $key)
->page();
DB::connect('sqlite')
->table('system_data')
->field('key,value')
->in('key', $key)
->count();
DB::connect('redis')->set('key', 1);
DB::connect('redis')->get('key');
DB::connect('redis')->incr('key');
DB::connect('redis')->decr('key');
DB::connect('redisCo')->set('swoole', 1);
DB::connect('redisCo')->get('swoole');
DB::connect('redisCo')->incr('swoole', 1.5);
DB::connect('redisCo')->decr('swoole', 2);
终结方法
one() multi() page() insert() insertAll() delete() count() sum() avg() min() max()
schemas() / table() 方法会进行一次clear,所以请放在前面
DB::connect('mysql')
->table('demo')
->equalTo('a',1)
->equalTo('b',1)
->closure('or')
->equalTo('c',1)
->equalTo('d',1)
->equalTo('e',1)
->closure('or')
->one();
DB::connect('pgsql')
->schemas('default')
->table('demo')
->equalTo('a',1)
->equalTo('b',1)
->closure('or')
->equalTo('c',1)
->equalTo('d',1)
->equalTo('e',1)
->closure('or',true)
->one();
try {
DB::connect('pgsql')->schemas('default')->table('data')->insert(['data' => 1]);
$lastId = DB::lastInsertId();
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
DB::connect()->table('demo')->equalTo('status',1)->fetchSql()->multi();
select * from "default".system_data where (data#>>'{project_name,name}')::text like '%系统%';
select * from "default".system_data where ("data"->'server_pre_alert_limit'->'value')::text::int > 5;
{project_name,name} % #TT || (({project_name,name} % #系统 || {project_name,name} != #xxx) && {server_pre_alert_limit,value} > #1 && ({server_pre_alert_limit,value} > #0 || {server_pre_alert_limit,value} < #100000000))
[ n ] isNull
{?,?,?} n #
[ !n ] isNotNull
{?,?,?} !n #
[ % ] like
{?,?,?} % #???
[ !% ] notLike
{?,?,?} !% #???
[ = ] equalTo
{?,?,?} = #???
[ > ] greaterThan
{?,?,?} > #???
[ < ] lessThan
{?,?,?} < #???
[ >= ] greaterThanOrEqualTo
{?,?,?} >= #???
[ <= ] lessThanOrEqualTo
{?,?,?} <= #???
[ <> , != ] notEqualTo
{?,?,?} <> #???
{?,?,?} != #???
[ >< ] between
{?,?,?} >< #???,???
[ !>< ] notBetween
{?,?,?} !>< #???,???
[ * ] any
{?,?,?} * #???,???,???...
[ ^ ] in
{?,?,?} ^ #???,???,???...
[ !^ ] notIn
{?,?,?} !^ #???,???,???...