A fully functional example for issue: byjg/php-micro-orm#9
Created
November 17, 2019 12:55
-
-
Save byjg/ba6dbfbe3424ad5da1471bd545e82598 to your computer and use it in GitHub Desktop.
ByJG Micro Orm with Snake Case
This file contains hidden or 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
{ | |
"name": "jg/snake_case", | |
"require": { | |
"byjg/micro-orm": "^4.0" | |
}, | |
"autoload": { | |
"psr-4": { | |
"ByJG\\Sample\\MicroOrm\\SnakeCase\\": "./" | |
} | |
} | |
} |
This file contains hidden or 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
<?php | |
require "vendor/autoload.php"; | |
// Creating the mapping | |
$mapper = new \ByJG\MicroOrm\Mapper( | |
\ByJG\Sample\MicroOrm\SnakeCase\MyTable::class, | |
'my_table', | |
'field_id' | |
); | |
$mapper->addFieldMap("fieldid", "field_id"); | |
$mapper->addFieldMap("fieldvalue", "field_value"); | |
$dataset = \ByJG\AnyDataset\Db\Factory::getDbRelationalInstance('sqlite://' . __DIR__ . '/snake_case.db'); | |
$repository = new \ByJG\MicroOrm\Repository($dataset, $mapper); | |
$repository->save(new \ByJG\Sample\MicroOrm\SnakeCase\MyTable("teste")); | |
var_dump($repository->get(1)); |
This file contains hidden or 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
<?php | |
class MyTable | |
{ | |
protected $field_id; | |
protected $field_value; | |
/** | |
* MyTable constructor. | |
* @param $field_value | |
*/ | |
public function __construct($field_value = "") | |
{ | |
$this->field_value = $field_value; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getFieldId() | |
{ | |
return $this->field_id; | |
} | |
/** | |
* @param mixed $field_id | |
*/ | |
public function setFieldId($field_id) | |
{ | |
$this->field_id = $field_id; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getFieldValue() | |
{ | |
return $this->field_value; | |
} | |
/** | |
* @param mixed $field_value | |
*/ | |
public function setFieldValue($field_value) | |
{ | |
$this->field_value = $field_value; | |
} | |
} |
This file contains hidden or 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
create table my_table ( | |
field_id integer primary key autoincrement not null, | |
field_value varchar(20) null | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment