Skip to content

emrancu/wpQueryBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

wpQueryBuilder

wpQueryBuilder provides a convenient, fluent interface to run database queries. It can be used to perform most database operations in your application.

Instalation

via Composer: composer require alemran/wp-query-builder

# Example
 
    require 'vendor/autoload.php';
    
    use wpQueryBuilder\DB;
    
    DB::table('demo')->first()

DB Functions
  1. Retrieving A Single Row
    DB::table('users')->first();
  2. Retrieving A multiple Row
    DB::table('users')->get();
  1. where($column, $value ) :
    DB::table('users')
         ->where('id', 1)
         ->get()
    DB::table('users')
         ->where(function($query){
           $query->where('id', 1);
           $query->orWhere('name', "name");
         })
         ->get()
  2. orWhere($column, $value) :
    DB::table('users')
         ->where('id', 1)
         ->orWhere('name', "name")
         ->get()
    DB::table('users')
         ->where('id', 1)
         ->orWhere(function($query){
             $query->where('field', 'value);
             $query->where('field', 'value);
             })
         ->first()
  3. whereRaw($query) :
    DB::table('users')
         ->whereRaw('id = 1')
         ->first()
  4. orWhereRaw($query) :
    DB::table('users')
         ->whereRaw('id = 1')
         ->orWhereRaw('id = 1')
         ->first()
  5. orderBy($columns, $direction) :
    DB::table('users')
         ->orderBy('id', 'desc')
    DB::table('users')
         ->orderBy('id,name', 'desc')
  6. groupBy($columns) :
    DB::table('users')
         ->groupBy('id')
    DB::table('users')
         ->groupBy('id,name')
  7. limit($number) :
    DB::table('users')
         ->where('id', 1)
         ->limit(number)->get()
  8. offset($number) :
    DB::table('users')
         ->where('id', 1)
         ->limit(number)->offset(number)->get()
  9. select($fields) :
    DB::table('users')
         ->select('id,name')
            ->get()
  10. insert($data) :
    DB::table('users')
         ->insert(['name' => "demo"])
  11. update($data,$where) :
    DB::table('users')
         ->where('id', 1)
         ->update(['name' => "demo"])
  12. delete($where) :
    DB::table('users')
         ->where('id', 1)
         ->delete()
  13. join($table, $first, $operator = null, $second = null) (INNER JOIN):
    DB::table('demo_notes as n')
            ->join('demo_users as u', 'u.id', '=', 'n.user_id')
            ->first()
    
    DB::table('demo_notes as n')
            ->join('demo_users as u', function($query){
              $query->on( 'u.id', '=', 'n.user_id')
              $query->orOn( 'u.id', '=', 'n.user_id')
            })
            ->first()
    
    DB::table('demo_notes as n')
            ->join('demo_users as u', function($query) use($request){
              $query->on( 'u.id', '=', 'n.user_id')
              $query->onWhere( 'u.id', '=', $request->id)
            })
            ->first()
    
    Note: Must use table alias for using join or leftJoin.
  14. leftJoin($table, $first, $operator = null, $second = null) (LEFT JOIN): Same as join()
  15. transaction():
    DB::startTransaction(function(){
        DB::table('demo_notes')
          ->insert([
             "note" => "Hello",
           ]);
    })
    DB::startTransaction(function(DB $query){
        $query->table('demo_notes')
          ->insert([
             "note" => "Hello",
           ]);
    })

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages