コード例 #1
0
 public function testQueryBuilder()
 {
     DB::schema('tab1', function ($tab) {
         $tab->id();
         $tab->string('Name')->unique();
         $tab->string('foo')->null();
         $tab->string('foDo')->default('abcde')->null();
         $tab->int('fo1os');
     });
     DB::startLog();
     DB::schema('tab2')->id()->alter();
     DB::schema('tab2')->bigint('tab1_id')->foreign('tab1', 'id')->alter();
     DB::schema('tab3')->id()->alter();
     DB::schema('tab3')->bigint('tab1_id')->foreign('tab1', 'id')->alter();
     DB::schema('tab3')->string('username')->unique()->alter();
     DB::schema('tab3_tab2')->bigint('tab3_id')->foreign('tab3', 'id')->alter();
     DB::schema('tab3_tab2')->bigint('tab2_id')->foreign('tab2', 'id')->alter();
     DB::schema('tab3_tab2')->bigint('taxi')->alter();
     DB::table('tab3_tab2')->truncate();
     DB::table('tab2')->truncate();
     DB::table('tab3')->truncate();
     DB::table('tab1')->truncate();
     $tab1_id = DB::table('tab1')->insert([['name' => md5(microtime()), 'foo' => null], ['name' => md5(microtime()), 'foo' => null], ['name' => md5(microtime()), 'foo' => '123']]);
     $tab2_id = DB::table('tab2')->insert(['tab1_id' => $tab1_id[0]]);
     $tab3_id = DB::table('tab3')->insert(['tab1_id' => $tab1_id[1], 'username' => md5(microtime())]);
     DB::table('tab3_tab2')->insert(['tab2_id' => $tab2_id[0], 'tab3_id' => $tab3_id[0], 'taxi' => 5]);
     DB::table('tab1')->insert(['name' => md5(microtime())]);
     /* --------------------------------------
     
                     JOIN
     
             --------------------------------------- */
     DB::table('tab2')->join('tab3_tab2', 'tab3_tab2.tab2_id', '=', 'tab2.id')->join('tab3', 'tab3_tab2.tab3_id', '=', 'tab3.id')->get();
     DB::table('tab3_tab2')->join(['tab3', 'tab2'])->get();
     DB::table('tab2 as ttt')->join('tab3_tab2')->join('tab3')->get();
     DB::table('tab2 as tb2')->join('tab3_tab2 as tb32', function ($q) {
         $q = $q->where('tb32.taxi', '=', 5);
         return $q;
     })->join('tab3')->get();
     DB::table('tab2')->join('tab3_tab2', function ($q) {
         $q = $q->on('tab3_tab2.tab2_id', '=', 'tab2.id');
         $q = $q->where('tab3_tab2.taxi', '=', 5);
         return $q;
     })->join('tab3')->get();
     DB::table('tab3_tab2')->join(['tab3' => function ($q) {
         $q = $q->where('tab3_tab2.taxi', '=', 5);
         return $q;
     }, 'tab2'])->get();
     DB::table('tab2')->join('tab3_tab2', function ($q) {
         $q = $q->on(function ($q) {
             return $q->orOn('tab3_tab2.tab2_id', '=', 'tab2.id')->orOn('tab3_tab2.tab2_id', '=', 'tab2.id');
         });
         $q = $q->on(function ($q) {
             return $q->orOn('tab3_tab2.tab2_id', '=', 'tab2.id')->orOn('tab3_tab2.tab2_id', '=', 'tab2.id');
         });
         $q = $q->where('tab3_tab2.taxi', '=', 5);
         return $q;
     })->join('tab3')->get();
     DB::table('tab2')->crossJoin('tab3_tab2')->join('tab3')->get();
     /*
     DB::table('tab1') -> insert(function(){
         return DB::table('tab1') -> select('name');
     });
     */
     /*
     DB::schema('tab3') -> dropColumn('username');
     DB::schema('tab3') -> drop();
     */
     DB::table(function () {
         return DB::table(function () {
             return DB::table('tab1');
         }, 'w43');
     })->union(DB::table('tab1'))->get();
     DB::table('tab1 as r')->orWhere(function ($q) {
         $q = $q->orWhere('foo', '123');
         $q = $q->orWhereIn('foo', ['123']);
         $q = $q->orWhereLike('foo', '%123%');
         $q = $q->orWhereNull('foo');
         $q = $q->orWhereNotNull('foo');
         $q = $q->orWhereNotBetween('foo', [1, 10]);
         $q = $q->orWhereBetween('foo', [1, 10]);
         return $q;
     })->orWhere(function ($q) {
         $q = $q->where('foo', '123');
         $q = $q->whereIn('foo', ['123']);
         $q = $q->whereLike('foo', '%123%');
         $q = $q->whereNull('foo');
         $q = $q->whereNotNull('foo');
         $q = $q->whereNotBetween('foo', [1, 10]);
         $q = $q->whereBetween('foo', [1, 10]);
         return $q;
     })->orHaving(function ($q) {
         $q = $q->orHaving('foo', '123');
         $q = $q->orHavingIn('foo', ['123']);
         $q = $q->orHavingLike('foo', '%123%');
         $q = $q->orHavingNull('foo');
         $q = $q->orHavingNotNull('foo');
         $q = $q->orHavingNotBetween('foo', [1, 10]);
         $q = $q->orHavingBetween('foo', [1, 10]);
         return $q;
     })->orHaving(function ($q) {
         $q = $q->having('foo', '123');
         $q = $q->havingIn('foo', ['123']);
         $q = $q->havingLike('foo', '%123%');
         $q = $q->havingNull('foo');
         $q = $q->havingNotNull('foo');
         $q = $q->havingNotBetween('foo', [1, 10]);
         $q = $q->havingBetween('foo', [1, 10]);
         return $q;
     })->get();
     DB::table('tab1 as r')->orWhere(function ($q) {
         $q = $q->orWhere('foo', '123');
         $q = $q->orWhereIn('foo', ['123']);
         return $q;
     })->where('id', function ($q) {
         return DB::table('tab2')->select('count(*)')->where('id', '=', 1)->orWhere(function ($q) {
             $q = $q->orWhere('foo', '123');
             return $q;
         });
     })->whereIn('foo', function ($q) {
         return DB::table('tab2')->select('count(*)')->where('id', '=', 1);
     })->whereNotIn('foo', function ($q) {
         return DB::table('tab2')->select('count(*)')->where('id', '=', 1);
     })->get();
     DB::table('tab1')->count();
     DB::table('tab1')->max('id');
     DB::table('tab1')->min('id');
     DB::table('tab1')->avg('id');
     DB::table('tab1')->where('id', 1)->update('foo', 'bla');
     DB::table('tab1')->where('id', 1)->update(['foo' => 'bla']);
     DB::table('tab1')->where('id', 1)->update([['id', 'foo']], [[0 => 'bla', 1 => 'cia']]);
 }
コード例 #2
0
ファイル: SchemaBuilder.php プロジェクト: EchoWine/database
 public function SQL_column($schema)
 {
     return DB::SQL()::COLUMN($schema->getName(), $schema->getType(), $schema->getLength(), $schema->getDefault(), $schema->getPrimary(), $schema->getUnique(), $schema->getAutoIncrement(), $schema->getNull());
 }
コード例 #3
0
ファイル: Repository.php プロジェクト: EchoWine/database
 /**
  * Alter the schema of database
  */
 public function alterSchema()
 {
     $fields = $this->getSchema()->getFields();
     if (empty($fields)) {
         return;
     }
     DB::schema($this->getSchema()->getTable(), function ($table) use($fields) {
         foreach ($fields as $name => $field) {
             $field->alter($table);
         }
     });
 }
コード例 #4
0
ファイル: QueryBuilder.php プロジェクト: EchoWine/database
 /**
  * Execute a reset query of the counter auto_increment
  *
  * @return object result of the query
  */
 public function resetAutoIncrement()
 {
     return $this->query(DB::SQL()::RESET_AUTOINCREMENT($this->getBuilderTable()));
 }
コード例 #5
0
ファイル: ORMTest.php プロジェクト: EchoWine/database
 public function log()
 {
     print_r(DB::log(true));
 }
コード例 #6
0
ファイル: DB.php プロジェクト: EchoWine/database
 /**
  * Create the table that will handle the restore
  */
 private static function iniRestore()
 {
     if (!self::$config['alter_schema']) {
         return;
     }
     $r = DB::schema('db_restore');
     $r->id()->alter();
     $r->string('table_restore')->alter();
     $r->string('table_from')->alter();
     self::confirm();
 }
コード例 #7
0
ファイル: BasicTest.php プロジェクト: EchoWine/database
 public function testRestore()
 {
     # --------------------------------------------------------------------------
     DB::query("TRUNCATE users");
     # --------------------------------------------------------------------------
     # Insert some data
     DB::query("INSERT INTO users (username,password) VALUES ('admin','admin')");
     # --------------------------------------------------------------------------
     # Save the table
     DB::save('users');
     # Perform some query
     DB::query("TRUNCATE users");
     # Now users is recovered!
     DB::undo();
     # Check
     $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 1);
     # --------------------------------------------------------------------------
     # Save the table
     DB::save('users');
     # Perform some query
     DB::query("TRUNCATE users");
     # Now users is empty!
     DB::confirm();
     # Check
     $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 0);
     # After several rows of code...
     # Restore the LAST SAVE POINT
     DB::restore();
     # Check
     $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 1);
     # --------------------------------------------------------------------------
     # But WAIT! You can undo the previous restore!
     DB::restore();
     # Check
     $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 0);
     # --------------------------------------------------------------------------
     # Oh yeah, restore the restore of restore point! (undo x3)
     DB::restore();
     # Check
     $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 1);
     # --------------------------------------------------------------------------
     DB::query("TRUNCATE users");
     # --------------------------------------------------------------------------
 }
コード例 #8
0
ファイル: kernel.php プロジェクト: EchoWine/gate-cms
class_alias("CoreWine\\Http\\Response\\Response", "Response");
class_alias("CoreWine\\Component\\Cache", "Cache");
class_alias("CoreWine\\Component\\Cfg", "Cfg");
# Make dir cache if doesn't exists
# Add cache dir
Cache::setDir(PATH_APP . '/cache/data');
# Initialize Handler
Handler::register();
Handler::add(\Kernel\Exceptions\ExceptionHandler::class);
# Initialize request
Request::ini();
# Initialize config
$config = (include PATH_CONFIG . '/app.php');
Cfg::add("app", $config);
\CoreWine\View\Engine::ini(PATH_APP . "/cache/views");
\CoreWine\DataBase\DB::connect($config['database']);
# Compile
\CoreWine\View\Engine::compile(PATH_APP, 'Resources/views');
foreach (\Kernel\Manager::$list as $name => $dir) {
    \CoreWine\View\Engine::compile(PATH_APP, "Resources/" . $name . "/views", $name);
}
\CoreWine\DataBase\ORM\SchemaBuilder::setFields(include PATH_CONFIG . '/orm.php');
# Load all sources
\Kernel\Manager::loadAll(PATH_SRC);
foreach (\Kernel\Manager::$list as $name => $dir) {
    \CoreWine\View\Engine::compile(PATH_SRC, $name . "/Resources/views", $name);
}
Cfg::set('app.drive.public', __DIR__ . "/../" . Cfg::get('app.public'));
Cfg::set('app.drive', __DIR__ . "/../");
# File Path
\CoreWine\DataBase\ORM\Field\File\Schema::setDefaultFilePath(Cfg::get('app.drive') . Cfg::get('app.public') . "uploads/");