Giter Site home page Giter Site logo

howdy_qb's Introduction

WP Query Builder

Relational Database Query builder for WordPress. WP Query Builder uses PDO for database queries. It has zero dependencies with third-party query builders or any other composer library.


Dev Envirenment Setup for Contributors

Want to contribute to this package? Please follow the steps below.

  • Create a local WordPress envirenment setup.
  • Create a basic plugin.
  • Run composer init into the plugin.
  • Clone [email protected]:CodesVault/howdy_qb.git into plugin folder.
  • Add repository for local package in plugin's composer.json.
            "repositories": [
                {
                    "type": "path",
                    "url": "./howdy_qb"
                }
            ],
            
  • Require this package. composer require "codesvault/howdy-qb @dev"


Examples

Create Table

DB::create('querybuilder')
    ->column('ID')->bigInt()->unsigned()->autoIncrement()->primary()->required()
    ->column('name')->string(255)->required()
    ->column('email')->string(255)->default('NULL')
    ->index(['ID'])
    ->execute();

// with foreign key
DB::create('howdy_qb')
    ->column('name')->string(255)->required()
    ->column('email')->string(255)->required()
    ->column('howdyID')->bigInt()->unsigned()
    ->foreignKey('howdyID', 'howdy', 'ID')
    ->execute();

Insert Statement

DB::insert('querybuilder', [
    [
        'name' => 'Keramot UL Islam',
        'email' => '[email protected]',
    ]
]);

Update Statement

DB::update('querybuilders', [
    'name' => 'Keramot UL',
    'email' => '[email protected]'
])
->where('ID', '=', 10)
->andWhere('name', '=', 'Abm Sourav')
->execute();

Select Statement

$result =
DB::select('qb.ID', 'qb.name, qb.email')
    ->from('querybuilders')
    ->alias('qb')
    ->groupBy('name')
    ->get();


// *** where clouse
$result =
DB::select('posts.ID', 'posts.post_title')
    ->distinct()
    ->from('posts posts')
    ->where('posts.post_status', '=', 'publish')
    ->orderBy('post_title', 'DESC')
    ->limit(10)->offset(2)
    ->get();

$result =
DB::select('posts.ID', 'posts.post_title')
    ->distinct()
    ->from('posts posts')
    ->where(function($query) {
        $query->where('posts.post_status', '=', 'publish')
            ->andWhere('posts.post_type', '=', 'page');
    })
    ->orderBy('post_title', 'DESC')
    ->get();


// *** JOIN
DB::select('users.display_name name')
    ->count('posts.ID', 'posts')
    ->from('users users')
    ->join('posts posts')
    ->where('posts.post_status', '=', 'publish')
    ->andWhere('posts.post_type', '=', 'post')
    ->get();

DB::select('posts.post_title')
    ->from('posts posts')
    ->innerJoin('term_relationships term_rel', 'posts.ID', 'term_rel.object_id')
    ->where('posts.post_status', '=', 'publish')
    ->get();

Delete Statement

// delete one row
DB::delete('posts')
    ->where('ID', '=', 3)
    ->execute();

// delete all records
DB::delete('posts')->execute();

// drop table
DB::delete('posts')
    ->drop()
    ->execute();

Expressions also can be exicuted with one instence of DB class. By doing this database connection will be stablished only once.

$db = new DB();

$result =
$db::select('posts.ID', 'posts.post_title')
    ...

$db::create('meta')
    ...

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.