protected function __construct($datastore) { $config = config::get('datastore', $datastore); $this->dbtype = $config['driver']; $this->pdo = new \PDO($config['driver'] . ':host=' . $config['host'] . ';dbname=' . $config['database'], $config['username'], $config['password']); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); }
/** * * Constructor. This will figure out which datastore the model uses (from config or default). * */ public function __construct() { $datastore = config::get($this, 'datastore'); if ($datastore != '') { $this->datastore = $datastore; } $map = config::get($this, 'mapDbToObject'); if (is_array($map)) { $this->mapDbToObject = $map; } if ($this->table == '') { $this->table = inflector::getSpecificfromcontext($this); } }
public static function query($query) { $shortq = preg_replace('/\\s*/m', '', $query); if (!self::$cachedStatements[$shortq] instanceof statement) { $lexer = new lexer(); $parsedQuery = $lexer->parse($query); $statement = new statement(); $statement->setQuery($parsedQuery); $datastore = $parsedQuery->getModel()->getDatastore(); $driverclass = '\\Moya\\core\\orm\\drivers\\' . config::get('datastore', $datastore . '/driver'); $driver = $driverclass::getInstance($datastore); $statement->setDriver($driver); $statement->setCompiledquery($driver->compileQuery($parsedQuery)); echo $statement->getCompiledquery() . "\n"; self::$cachedStatements[$shortq] = $statement->prepare(); } return self::$cachedStatements[$shortq]; }
protected function parseSubselect(lexer $lexer) { $subtokens = array(); $nested = 0; $lexer->movenext(); while ($lexer->getCurrentToken() != ')' && $nested == 0) { $subtokens[] = $lexer->getCurrentToken(); $lexer->moveNext(); if ($lexer->getCurrentToken() == '(') { $nested++; } elseif ($lexer->getCurrentToken() == ')') { $nested--; } } $sublexer = new lexer(); $subquery = $sublexer->parse($subtokens); $datastore = $subquery->getModel()->getDatastore(); $driverclass = '\\Moya\\core\\orm\\drivers\\' . config::get('datastore', $datastore . '/driver'); $driver = $driverclass::getInstance($datastore); $compiledSubquery = $driver->compileQuery($subquery); //TODO subselects over different datastores; return $compiledSubquery; }