public function __construct(Database $model) { /* CLI case */ if (!defined('APPLICATION_ENV')) { define('APPLICATION_ENV', 'production'); } $this->model = $model; $this->db = Database::instance('system', 'archive'); }
public static function __callStatic($method, $args) { $db = Inflector::uncamelize($method); if (fnmatch('*_*', $db)) { list($database, $table) = explode('_', $db, 2); } else { $database = SITE_NAME; $table = $db; } if (!count($args)) { return Db::instance($database, $table); } elseif (count($args) == 1) { $id = Arrays::first($args); if (is_numeric($id)) { return Db::instance($database, $table)->find($id); } } }
public static function flush($db = null, $table = null, $name = null) { $db = is_null($db) ? '*' : $db; $table = is_null($table) ? '*' : $table; $name = is_null($name) ? '*' : Inflector::urlize($name, '.'); if ($db != '*' && $table != '*') { $cache = Database::instance($db, $table)->cache(); } else { $cache = Database::instance('auth', 'user')->cache(); } $hashes = $cache->keys("dbjson::cachedQueries::{$db}::{$table}"); $ages = $cache->keys("dbjson::cachedQueries::{$db}::{$table}::{$name}::age"); if (count($hashes)) { foreach ($hashes as $hash) { $cache->del($hash); } } if (count($ages)) { foreach ($ages as $age) { $cache->del($age); } } }
public static function __callStatic($method, $args) { $instance = Db::instance(static::$database, static::$table); return call_user_func_array([$instance, $method], $args); }
function coreCache() { return \Dbjson\Dbjson::instance(); }
public static function instance($db, $table) { return Driver::instance($db, $table); }
public static function depopulate($database = null) { $database = is_null($database) ? SITE_NAME : $database; $tables = glob(Config::get('directory.store', STORAGE_PATH) . DS . 'dbjson' . DS . $database . '_' . APPLICATION_ENV . DS . '*'); $tableDir = Arrays::first($tables); $table = Arrays::last(explode(DS, $tableDir)); $db = Db::instance($database, $table); $db->cache()->flushall(); }
public function create($db, $table, Closure $next = null) { $this->model = Database::instance($db, $table); $this->singular = ucfirst($table); $this->plural = substr($this->singular, -1) != 's' ? $this->singular . 's' : $this->singular; $this->order = 'id'; if (!is_null($next)) { $next($this); } }