增加一条数据-快捷方法

@param array $data 要新增的数据
@param string $tableName 表名 不传会自动从当前Model中$table属性获取
@param mixed $tablePrefix 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀

@return int
340547
public function set($data, $tableName = null, $tablePrefix = null)
    {
        is_null($tableName) && $tableName = $this->getTableName();
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        return $this->db($this->getDbConf())->set($tableName, $data, $tablePrefix);
    }
1055311
public function table($table = '', $tablePrefix = null)
    {
        $hasAlias = is_array($table) ? true : false;
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        $tableName = $tablePrefix . ($hasAlias ? key($table) : $table);

        $this->table[count($this->table) . '_' . $tableName] = $hasAlias ? current($table) : null;
        return $this;
    }
719676
public function update($table, array $data, $where = [], array $bind = [])
    {
        $table  = $this->quote()->identifier($table);
        $fields = [];
        foreach ($data as $field => $value) {
            $fields[] = $this->quote()->into("{$field} = ?", $value);
        }
        $sql = "UPDATE $table SET " . implode(', ', $fields);
        if (is_array($where)) {
            $where = $this->createWhereExpression($where);
        }
        $sql .= (($where) ? " WHERE {$where}" : '');

        $stmt = $this->query($sql, $bind);

        return $stmt->rowCount();
    }
897413
public function increment($key, $val = 1, $field = null, $tablePrefix = null)
    {
        list($tableName, $condition) = $this->parseKey($key, true);
        if (is_null($field) || empty($tableName) || empty($condition)) {
            return false;
        }
        $val = abs(intval($val));
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        $tableName = $tablePrefix . $tableName;

        $bulk = new BulkWrite();
        $bulk->update($condition, ['$inc' => [$field => $val]], ['multi' => true]);
        $result = $this->runMongoBulkWrite($tableName, $bulk);

        Cml::$debug && $this->debugLogSql('BulkWrite INC', $tableName, $condition, ['$inc' => [$field => $val]]);

        return $result->getModifiedCount();
    }
6263
public function replace($table, $data) {

        $_fileds = '';
        $_values = '';
        $_T_fields = $this->getTableFields($table);
        foreach ( $data as $_key => $_val ) {

            //自动过滤掉不存在的字段
            if ( !in_array( $_key, $_T_fields ) ) continue;

            $_fileds .= ( $_fileds=='' ) ? "`{$_key}`" : ", `{$_key}`";
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_values .= ( $_values=='' ) ? "{$_val}" : ",{$_val}";
        }

        if ( $_fileds != '' ) {
            $_query = "REPLACE INTO {$table}(" . $_fileds . ") VALUES(" . $_values . ")";
            if ( $this->execute($_query) != false ) {
                return true;
            }

        }
        return false;
    }
619388
public static function getRawTableName($name, $tablePrefix = '')
    {
        if (false !== strpos($name, '{{')) {
            $name = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $name);

            return str_replace('%', $tablePrefix, $name);
        }

        return $name;
    }
115598
public function delByColumn($val, $column = null, $tableName = null, $tablePrefix = null)
    {
        is_null($tableName) && $tableName = $this->getTableName();
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        is_null($column) && $column = $this->db($this->getDbConf())->getPk($tableName, $tablePrefix);
        return $this->db($this->getDbConf())->where($column, $val)
            ->delete($tableName, true, $tablePrefix);
    }
382986
public function update($table, $data, $condition)
    {
        if ( empty($condition) ) return false;
        $_T_fields = $this->getTableFields($table);
        $_keys = '';
        foreach ( $data as $_key => $_val ) {

            //过滤不存在的字段
            if ( !in_array($_key, $_T_fields) ) continue;
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_keys .= $_keys == ''? "`{$_key}`={$_val}" : ", `{$_key}`={$_val}";
        }
        if ( $_keys !== '' ) {
            $_query = "UPDATE {$table} SET " . $_keys . $condition;
            $result = $this->execute($_query);
            if ( $result != false ) {
                return $result->rowCount() > 0 ? $result->rowCount() : true;
            }
        }
        return false;
    }
393916
public function insertOrUpdate($tableName, array $data)
    {
        $this->executeQuery("SET SESSION sql_mode='ALLOW_INVALID_DATES'", []);

        $columns = array_map(
            array($this, 'getQuotedName'),
            array_keys($data)
        );
        $updateAssignments = $this->getAssignmentsFor($data);
        return sprintf(
            "INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s",
            $this->getQuotedName($tableName),
            implode(', ', $columns),
            implode(', ', array_fill(0, count($data), '?')),
            $updateAssignments
        );
    }
27634
public function getTableLimit($tableName)
    {
        if (empty($this->tableLimits[$tableName])) {
            return false;
        }

        $limit = $this->tableLimits[$tableName];
        if (!is_numeric($limit)) {
            return false;
        }

        return $limit;
    }
1213403
public function pushDoc($appName, $tableName, $data) {
        if(!$appName || !$tableName || !$data || !is_array($data)){
            return $this->error('参数有误');
        }
        $documentClient = new DocumentClient($this->client);
        $response = $documentClient->push(json_encode($data), $appName, $tableName);
        return $this->parseResponse($response, '推送文档');
    }
1249539
private static function collect($data, $table, $key)
    {
        $class = get_called_class();
        $object = new $class();
        $collection = new Collection();
        //
        if (Table::count($data) > 0) {
            foreach ($data as $row) {
                $rows[0] = $row;
                //
                $value =
                [
                    'name'        => $object->_model,
                    'prifixTable' => $object->_prifixTable,
                    'columns'     => $object->_columns,
                    'key'         => $object->_keyName,
                    'values'      => $rows,
                ];
                //
                $collection->add(new $class($value));
            }
        }
        //
        return $collection;
    }
614945
public function getTableSize($table) {
        $table = $this->getPrefix() . $table;
        $sql   = "show table status from " . $this->config['table'];
        $data  = $this->query($sql);
        foreach ($data as $v) {
            if ($v['Name'] == $table) {
                return $v['Data_length'] + $v['Index_length'];
            }
        }
        return 0;
    }
505097
public S tableNamePrefix(String tableNamePrefix) {
      attributes.attribute(TABLE_NAME_PREFIX).set(tableNamePrefix);
      return self();
   }
1019200
public function update($table_name, $id, array $data) {
            Event::dispatch(EventData::forBefore(Event::BEFORE_UPDATE, $table_name, $data), $data);


            $q = $this->config->getSystemIdentifierQuote();

            //update database record
            $sql_query = "UPDATE $q" . $table_name . "$q SET ";

            $statement_params = [':update_id' => $id];
            // keep track of null params for logging output. binding null params
            // was causing foreign key violations (for nullable fields)
            $null_params = [];
            foreach ($data as $field_name => $value) {
                if (strtolower($value) == 'null' || is_null($value)) {
                    $sql_query .= "\n$q" . $field_name . "$q = NULL,";
                    $null_params[ $field_name ] = 'NULL';
                } else {
                    $sql_query .= "\n$q" . $field_name . "$q = :" . $field_name . ",";
                    $statement_params[ ':' . $field_name ] = $value;
                }
            }

            $full_param_list = array_merge($null_params, $statement_params);

            $sql_query = substr($sql_query, 0, -1); // remove trailing comma
            $sql_query .= "\nWHERE $q" . 'id' . "$q = :update_id";
            $sql_query .= ";";

            try {
                //Run update query, collect stats
                $stmt = $this->db_connection->prepare($sql_query);
                if ($statement_params) {
                    foreach ($statement_params as $k => $v) {
                        $stmt->bindValue($k, $v);
                    }
                }

                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $sql_query, $full_param_list));

                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }

            $row_count = $stmt->rowCount();
            Event::dispatch(EventData::forAfter(Event::AFTER_UPDATE, $table_name, $full_param_list, $sql_query, $row_count));

            return $row_count;
        }
365354
public function join($table, $on, $tablePrefix = null)
    {
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;

        $this->table($table, $tablePrefix);
        $hasAlias = is_array($table) ? true : false;

        $tableName = $tablePrefix . ($hasAlias ? key($table) : $table);
        $this->join[count($this->table) - 1 . '_' . $tableName] = is_array($on) ? $this->parseOn($table, $on) : addslashes($on);
        return $this;
    }
1163498
public function setTableName($tableName)
    {
        $this->tableName = $tableName;
        $this->setPrefix($this->generatePrefix($tableName));
        return $this;
    }