Example #1
0
function hydrate_model($file)
{
    if (is_file($file) && strpos($file, '.php')) {
        preg_match_all('/class\\s(\\S+)\\s/', read($file), $match);
        require $file;
        foreach ($match[1] as $klass) {
            $re = new \ReflectionClass($klass);
            switch ($re->getParentClass()->getName()) {
                case 'Servant\\Mapper\\Database':
                    status('hydrate', $file);
                    $dsn = option('database.' . $klass::CONNECTION);
                    $db = \Grocery\Base::connect($dsn);
                    $columns = $klass::columns();
                    $indexes = $klass::indexes();
                    if (!isset($db[$klass::table()])) {
                        $db[$klass::table()] = $columns;
                    }
                    \Grocery\Helpers::hydrate($db[$klass::table()], $columns, $indexes);
                    break;
                case 'Servant\\Mapper\\MongoDB':
                    status('hydrate', $file);
                    $dsn_string = \Servant\Config::get($klass::CONNECTION);
                    $database = substr($dsn_string, strrpos($dsn_string, '/') + 1);
                    $mongo = $dsn_string ? new \Mongo($dsn_string) : new \Mongo();
                    $db = $mongo->{$database ?: 'default'};
                    \Servant\Helpers::reindex($db->{$klass::table()}, $klass::indexes());
                    break;
                default:
                    break;
            }
        }
    }
}
Example #2
0
 public function unserialize($data)
 {
     extract(unserialize($data));
     $this->setup = $params;
     $this->conn = \Grocery\Base::factory($params, TRUE);
     $type = \Grocery\Config::get('unserialize');
     if ($type === 'reset') {
         $this->reset();
     }
     foreach ($tables as $one => $set) {
         if ($type === 'overwrite') {
             $this->drop($one);
         }
         if (!isset($this->{$one})) {
             $this->create($one, $set['columns']);
             foreach ($set['indexes'] as $key => $val) {
                 $this->add_index($one, $key, $val['column'], $val['unique']);
             }
         }
     }
 }
Example #3
0
<?php

describe('Grocery', function () {
    $datasources = array_filter(array('sqlite::memory:', 'sqlite::memory:#pdo', 'mysql://root@localhost/grocery', 'mysql://root@localhost/grocery#pdo', getenv('CI') && !defined('HHVM_VERSION') ? 'pgsql://postgres@localhost/grocery' : '', getenv('CI') && !defined('HHVM_VERSION') ? 'pgsql://postgres@localhost/grocery#pdo' : ''));
    $suitcase = function ($conn) {
        $db = \Grocery\Base::connect($conn);
        $version = json_encode($db->version());
        describe("Using {$conn} / {$version}", function () use($db) {
            let('db', $db->reset());
            // describe('Base', function () {
            //   xit('TODO', function ($db) {});
            // });
            // describe('Database', function () {
            //   describe('Debug', function () {
            //     xit('TODO', function ($db) {});
            //   });
            //   describe('Forge', function () {
            //     xit('TODO', function ($db) {});
            //   });
            //   describe('Scheme', function () {
            //     xit('TODO', function ($db) {});
            //   });
            //   describe('SQL', function () {
            //     describe('Base', function () {
            //       xit('TODO', function ($db) {});
            //     });
            //     describe('Dump', function () {
            //       xit('TODO', function ($db) {});
            //     });
            //     describe('Query', function () {
            //       xit('TODO', function ($db) {});