/** * Constructs the PostgreSQL adapter and sets the default port to 5432. * * @param array $config Configuration options for this class. Available options * defined by this class: * - `'host'` : _string_ The IP or machine name where PostgreSQL is running, * followed by a colon, followed by a port number or socket. * Defaults to `'localhost:5432'`. * - `'schema'` : _string_ The name of the database schema to use. Defaults to 'public' * - `'timezone'`: _stirng_ The database timezone. Defaults to `null`. */ public function __construct($config = []) { $defaults = ['host' => 'localhost:5432', 'schema' => 'public', 'timezone' => null, 'classes' => ['dialect' => 'sql\\dialect\\PostgreSql'], 'handlers' => ['cast' => ['boolean' => function ($value, $options = []) { return $value === 't'; }], 'datasource' => ['boolean' => function ($value, $options = []) { return $value ? 'true' : 'false'; }, 'array' => function ($data) { $data = (array) $data; $result = []; foreach ($data as $value) { if (is_array($value)) { $result[] = $this->_handlers['datasource']['array']($value); } else { $value = str_replace('"', '\\"', $value); if (!is_numeric($value)) { $value = '"' . $value . '"'; } $result[] = $value; } } return '{' . join(",", $result) . '}'; }]]]; $config = Set::merge($defaults, $config); parent::__construct($config + $defaults); $this->formatter('datasource', 'array', $this->_handlers['datasource']['array']); }
/** * Constructs the Sqlite adapter and sets the default port to 3306. * * @param array $config Configuration options for this class. Available options: * - `'database'` _string_ : database path. Defaults to `':memory:'`. */ public function __construct($config = []) { $defaults = ['database' => ':memory:', 'classes' => ['dialect' => 'Lead\\Sql\\Dialect\\Sqlite'], 'handlers' => []]; $config = Set::merge($defaults, $config); parent::__construct($config); $this->formatter('datasource', 'boolean', function ($value, $options) { return $value ? '1' : '0'; }); }
/** * Constructs the MySQL adapter and sets the default port to 3306. * * @param array $config Configuration options for this class. Available options * defined by this class: * - `'host'`: _string_ The IP or machine name where MySQL is running, * followed by a colon, followed by a port number or socket. * Defaults to `'localhost:3306'`. */ public function __construct($config = []) { $defaults = ['host' => 'localhost:3306', 'classes' => ['dialect' => 'Lead\\Sql\\Dialect\\MySql'], 'handlers' => []]; $config = Set::merge($defaults, $config); parent::__construct($config); }
/** * Constructs the Sqlite adapter and sets the default port to 3306. * * @param array $config Configuration options for this class. Available options: * - `'database'` _string_ : database path. Defaults to `':memory:'`. */ public function __construct($config = []) { $defaults = ['database' => ':memory:', 'classes' => ['dialect' => 'sql\\dialect\\Sqlite'], 'handlers' => []]; $config = Set::merge($defaults, $config); parent::__construct($config); }