<commit_before><?php
/**
 * Main Class of Tsukiyo Framework
 *
 * PHP versions 5
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 */

require_once(dirname(__FILE__) . '/Orm.php');
require_once(dirname(__FILE__) . '/Driver/Factory.php');

/**
 * Main Class of Tsukiyo Framework
 *
 * @author    <NAME> <<EMAIL>>
 */
class Tsukiyo_Db
{
    protected $config = array('dsn' => '',
                              'autoConfig' => true,
                              'configFile' => 'cache/tables.ini',
                              'voPrefix' => 'Vo_');

    /**
     * Set dsn
     */
    public function setDsn($dsn)
    {
        $this->config['dsn'] = $dsn;
    }
    /**
     * Set auto generate config file
     */
    public function setAutoConfig($auto)
    {
        $this->config['autoConfig'] = $auto;
    }
    /**
     * Set config file path
     */
    public function setConfigFile($path)
    {
        $this->config['configFile'] = $path;
    }
    public function setVoPrefix($prefix){
        $this->config['voPrefix'] = $prefix;
    }

    public function generateVo($name){
        return $this->create($name)->emptyVo();
    }

    public function from($name){
        return $this->create($name);
    }

    public function autoload($className){
        if (preg_match('/^' . $this->config['voPrefix'] . '/', $className)){
            $name = str_replace($this->config['voPrefix'], '', $className);
            $this->generateVo($name);
        }
    }

    public function create($name){
        $driver = $this->getDriver();
        return new Tsukiyo_Orm($driver, $this->config['configFile'], $name,
                               $this->config['voPrefix']);
    }

    private function voToDbName($vo){
        return str_replace($this->config['voPrefix'], '', get_class($vo));
    }
    public function save($vo){
        return $this->create($this->voToDbName($vo))->save($vo);
    }
    public function insert($vo){
        return $this->create($this->voToDbName($vo))->insert($vo);
    }
    public function update($vo){
        return $this->create($this->voToDbName($vo))->update($vo);
    }
    public function delete($vo, $ids = null){
        if (is_string($vo) && $ids){
            $orm = $this->create($vo);
            $arg = $ids;
        }else{
            $orm = $this->create($this->voToDbName($vo));
            $arg = $vo;
        }
        return $orm->delete($arg);
    }

    public function getDriver(){
        try {
            $db = Tsukiyo_Driver_Factory::factory($this->config['dsn']);
            return $db;
        }catch (PDOException $e){
            // PDO error
            trigger_error($e->getMessage(), E_USER_ERROR);
        }catch (Exception $e){
            // framework error
            trigger_error($e->getMessage(), E_USER_ERROR);
        }
    }
}
<commit_msg>add supporting method chain of Db, change prefix of vo.<commit_after><?php
/**
 * Main Class of Tsukiyo Framework
 *
 * PHP versions 5
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 */

require_once(dirname(__FILE__) . '/Orm.php');
require_once(dirname(__FILE__) . '/Driver/Factory.php');

/**
 * Main Class of Tsukiyo Framework
 *
 * @author    <NAME> <<EMAIL>>
 */
class Tsukiyo_Db
{
    protected $config = array('dsn' => '',
                              'autoConfig' => true,
                              'configFile' => 'cache/tables.ini',
                              'voPrefix' => 'Tsukiyo_Vo_');

    /**
     * Set dsn
     */
    public function setDsn($dsn)
    {
        $this->config['dsn'] = $dsn;
        return $this;
    }
    /**
     * Set auto generate config file
     */
    public function setAutoConfig($auto)
    {
        $this->config['autoConfig'] = $auto;
        return $this;
    }
    /**
     * Set config file path
     */
    public function setConfigFile($path)
    {
        $this->config['configFile'] = $path;
        return $this;
    }
    public function setVoPrefix($prefix){
        $this->config['voPrefix'] = $prefix;
        return $this;
    }

    public function generateVo($name){
        return $this->create($name)->emptyVo();
    }

    public function from($name){
        return $this->create($name);
    }

    public function autoload($className){
        if (preg_match('/^' . $this->config['voPrefix'] . '/', $className)){
            $name = str_replace($this->config['voPrefix'], '', $className);
            $this->generateVo($name);
        }
    }

    public function create($name){
        $driver = $this->getDriver();
        return new Tsukiyo_Orm($driver, $this->config['configFile'], $name,
                               $this->config['voPrefix']);
    }

    private function voToDbName($vo){
        return str_replace($this->config['voPrefix'], '', get_class($vo));
    }
    public function save($vo){
        return $this->create($this->voToDbName($vo))->save($vo);
    }
    public function insert($vo){
        return $this->create($this->voToDbName($vo))->insert($vo);
    }
    public function update($vo){
        return $this->create($this->voToDbName($vo))->update($vo);
    }
    public function delete($vo, $ids = null){
        if (is_string($vo) && $ids){
            $orm = $this->create($vo);
            $arg = $ids;
        }else{
            $orm = $this->create($this->voToDbName($vo));
            $arg = $vo;
        }
        return $orm->delete($arg);
    }

    public function getDriver(){
        try {
            $db = Tsukiyo_Driver_Factory::factory($this->config['dsn']);
            return $db;
        }catch (PDOException $e){
            // PDO error
            trigger_error($e->getMessage(), E_USER_ERROR);
        }catch (Exception $e){
            // framework error
            trigger_error($e->getMessage(), E_USER_ERROR);
        }
    }
}

{'fraction_non_alphanumeric': 0.17027863777089783, 'fraction_numerical': 0.0017199862401100791, 'mean_word_length': 2.0429094714809, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7328019', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1734, 'n_words': 343}