Giter Club home page Giter Club logo

wpquerybuilder's Introduction

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",
           ]);
    })

wpquerybuilder's People

Contributors

emrancu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.