Skip to content

Commit

Permalink
added many insert, lists function added ordering variable and bugs fi…
Browse files Browse the repository at this point in the history
…xed.
  • Loading branch information
bertugfahriozer committed Jan 22, 2023
1 parent 4defaaf commit c82017d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/Models/CommonModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public function __construct(string $group = 'default')
$this->db = \Config\Database::connect($group);
}

public function lists(string $table, string $select = '*', array $where = [])
public function lists(string $table, string $select = '*', array $where = [], $order = 'id ASC')
{
$builder = $this->db->table($table);
return $builder->select($select)->where($where)->get()->getResult();
return $builder->select($select)->where($where)->orderBy($order)->get()->getResult();
}

public function create(string $table, array $data = [])
Expand All @@ -22,6 +22,12 @@ public function create(string $table, array $data = [])
return $builder->insertID();
}

public function createMany(string $table, array $data)
{
$builder = $this->db->table($table);
return $builder->insertBatch($data);
}

public function edit(string $table, array $data = [], array $where = [])
{
$builder = $this->db->table($table);
Expand All @@ -40,14 +46,14 @@ public function selectOne(string $table, array $where = [], string $select = '*'
return $builder->select($select)->where($where)->get()->getRow();
}

public function whereInCheckData($att, array $where = [], string $table)
public function whereInCheckData(string $att, string $table, array $where = [])
{
$builder = $this->db->table($table);
return $builder->whereIn($att, $where, 1)->get()->getNumRows();

}

public function isHave(string $table, $where)
public function isHave(string $table, array $where)
{
$builder = $this->db->table($table);
return $builder->getWhere($where, 1)->getNumRows();
Expand All @@ -59,7 +65,7 @@ public function count(string $table, array $where = [])
return $builder->where($where)->countAllResults();
}

public function research(array $like = [], string $table, string $select = '*', array $where = [])
public function research(string $table, array $like = [], string $select = '*', array $where = [])
{
$builder = $this->db->table($table);
return $builder->select($select)->where($where)->like($like)->get()->getResult();
Expand Down

0 comments on commit c82017d

Please sign in to comment.