hoangm / query
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
pkg:composer/hoangm/query
Requires (Dev)
- symfony/var-dumper: ^6.2
This package is auto-updated.
Last update: 2025-11-28 16:28:28 UTC
README
Người thực hiện: Ngô Minh Hòa
Installation
composer require "hoangm/query @dev"
Configuration
- Create a config.ini file in root folder with content
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database_name DB_USERNAME=root DB_PASSWORD=
and customize it
Usage examples
-
Use Query Builder
<?php require 'vendor/autoload.php'; use Hoangm\Query\DB; $user = DB::table('users')->get();
-
Use Model Builder
-
Create a model class
<?php namespace App\Models; use Hoangm\Query\Model; class User extends Model { protected static $table = 'users'; // table name protected static $primary_key = 'id'; // primary key }
- Usage
<?php require 'vendor/autoload.php'; use App\Models\User; $user = User::all();
-
Methods
Query Builder
-
table($table_name)- Set table name
-
select($columns)- Select columns
- Example:
select('id, name')orselect(['id', 'name'])
-
where($column, $operator, $value)- Where condition
- Example:
where('id', '=', 1)orwhere(['id' => 1])
-
orWhere($column, $operator, $value)- Or where condition
- Example:
orWhere('id', '=', 1)ororWhere(['id', '=', 1], ['name', '=', 'Hoang'])
-
orderBy($column, $order)- Order by
- Example:
orderBy('id', 'desc')
-
limit($limit)- Limit
- Example:
limit(10)
-
offset($offset)- Offset
- Example:
offset(10)
-
join($table, $first, $operator, $second)- Inner Join
- Example:
join('users', 'users.id', '=', 'posts.user_id')
-
leftJoin($table, $first, $operator, $second)- Left Join
- Example:
leftJoin('users', 'users.id', '=', 'posts.user_id')
-
having($column, $operator, $value)- Having
- Example:
having('id', '=', 1)orhaving(['id' => 1])
-
insert($data)- Insert data
- Example:
insert(['name' => 'Hoang', 'email' => 'hoangominh01@gmail.com'])
-
update($data)- Update data
- Example:
update(['name' => 'Hoang2'])->where('id', '=', 1)
-
delete()- Delete data
- Example:
delete()->where('id', '=', 1)
-
get()- Get data
- Example:
get()
-
count()- Count data
- Example:
count()
-
first()- Get first data
- Example:
first()
Model Builder
-
all()- Get all data
- Example:
all()
-
find($id)- Find data by id
- Example:
find(1)
-
create($data)- Create data
- Example:
create(['name' => 'Hoang', 'email' => 'hoangominh01@gmail.com'])