added autochatc database handler from DBmodel instance,
added set rootDir for Creator, added deduct numeric (unix timestamp) for datetime column, added method existsTable for Maintenance
This commit is contained in:
@ -4,10 +4,19 @@ namespace TPsoft\DBmodel;
|
||||
|
||||
class Creator {
|
||||
|
||||
private $dbh;
|
||||
private DBmodel $dbh;
|
||||
private string $rootDir = '';
|
||||
|
||||
public function __construct($dbh) {
|
||||
$this->dbh = $dbh;
|
||||
public function __construct(?DBmodel $dbh = null) {
|
||||
if (is_null($dbh)) {
|
||||
if (!is_null(DBmodel::$instance)) {
|
||||
$this->dbh = DBmodel::$instance;
|
||||
} else {
|
||||
throw new \Exception('DB handler is null');
|
||||
}
|
||||
} else {
|
||||
$this->dbh = $dbh;
|
||||
}
|
||||
}
|
||||
|
||||
public function interact() {
|
||||
@ -97,7 +106,7 @@ class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
||||
|
||||
public $"."tables = array(
|
||||
'".$entity."' => array(
|
||||
'name' => '".$entity."',
|
||||
'name' => '".$tablename."',
|
||||
'primary_key_name' => ".$primary_key_name.",
|
||||
'allow_attributes' => array(
|
||||
".implode(",\n\t\t\t\t", $allowed_attributes)."
|
||||
@ -166,11 +175,14 @@ class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
||||
return $line;
|
||||
}
|
||||
|
||||
public function rootDir() {
|
||||
public function rootDir(?string $dir = null) {
|
||||
if (!is_null($dir)) {
|
||||
$this->rootDir = $dir;
|
||||
}
|
||||
if (strlen($this->rootDir) > 0) return $this->rootDir;
|
||||
return dirname(dirname(__FILE__));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user