-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added column casting feature for data insertion
- Loading branch information
1 parent
7af0c5b
commit 10cd5a9
Showing
10 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Tests\Models\Example3; | ||
|
||
class CastsTest extends TestCase | ||
{ | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
Example3::truncate(); | ||
} | ||
|
||
public function testCasts() | ||
{ | ||
Example3::insertAssoc([['f_int' => 1, 'f_bool' => false]]); | ||
$rows = Example3::where('f_int', 1)->getRows(); | ||
$this->assertEquals(false, $rows[0]['f_bool']); | ||
|
||
Example3::truncate(); | ||
Example3::insertBulk([[2, false]], ['f_int', 'f_bool']); | ||
$rows = Example3::where('f_int', 2)->getRows(); | ||
$this->assertEquals(false, $rows[0]['f_bool']); | ||
|
||
Example3::truncate(); | ||
$one = new Example3(); | ||
$one->f_int = 3; | ||
$one->f_bool = false; | ||
$one->save(); | ||
$rows = Example3::where('f_int', 3)->getRows(); | ||
$this->assertEquals(false, $rows[0]['f_bool']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Tests\Models; | ||
|
||
use PhpClickHouseLaravel\BaseModel; | ||
|
||
/** | ||
* @property bool $f_bool | ||
* @property int $f_int | ||
*/ | ||
class Example3 extends BaseModel | ||
{ | ||
protected $table = 'examples3'; | ||
protected $casts = ['f_bool' => 'boolean']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
return new class extends \PhpClickHouseLaravel\Migration { | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
static::write( | ||
" | ||
CREATE TABLE IF NOT EXISTS examples3 ( | ||
created_at DateTime64 DEFAULT now64(), | ||
f_int Int64, | ||
f_string String, | ||
f_bool Bool | ||
) | ||
ENGINE = MergeTree() | ||
ORDER BY (f_int) | ||
" | ||
); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
static::write('DROP TABLE examples3'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters