Skip to content

Commit

Permalink
Merge pull request #26
Browse files Browse the repository at this point in the history
  • Loading branch information
AbmSourav authored Jun 30, 2023
2 parents fcb10df + 41c83af commit fd05c4d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This Query Builder is also used in [Kathamo](https://kathamo.dev) Framework. Kat
DB::create('querybuilder')
->column('ID')->bigInt()->unsigned()->autoIncrement()->primary()->required()
->column('name')->string(255)->required()
->column('email')->string(255)->default('NULL')
->column('email')->string(255)->nullable()
->index(['ID'])
->execute();
```
Expand Down
42 changes: 22 additions & 20 deletions src/Api/CreateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,43 @@

interface CreateInterface
{
function column(string $column_name): self;
public function column(string $column_name): self;

function int(int $size = 255): self;
public function int(int $size = 255): self;

function bigInt(int $size = 255): self;
public function bigInt(int $size = 255): self;

function double(int $size = 255, int $d = 2): self;
public function double(int $size = 255, int $d = 2): self;

function boolean(): self;
public function boolean(): self;

function string(int $size = 255): self;
public function string(int $size = 255): self;

function text(int $size = 10000): self;
public function text(int $size = 10000): self;

function longText(int $size): self;
public function longText(int $size): self;

function required(): self;
public function required(): self;

function primary($columns = []): self;
public function nullable(): self;

function index(array $columns): self;
public function primary($columns = []): self;

function date(): self;
public function index(array $columns): self;

function dateTime(): self;
public function date(): self;

function unsigned(): self;
public function dateTime(): self;

function autoIncrement(): self;
public function unsigned(): self;

function default($value): self;
public function autoIncrement(): self;

function foreignKey(string $column, string $reference_table, string $reference_column): self;
public function default($value): self;

function getSql();

function execute();
public function foreignKey(string $column, string $reference_table, string $reference_column): self;

public function getSql();

public function execute();
}
14 changes: 7 additions & 7 deletions src/Api/DeleteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

interface DeleteInterface
{
function where($column, string $operator = null, string $value = null): self;
public function where($column, string $operator = null, string $value = null): self;

function andWhere(string $column, string $operator = null, string $value = null): self;
public function andWhere(string $column, string $operator = null, string $value = null): self;

function orWhere(string $column, string $operator = null, string $value = null): self;
public function orWhere(string $column, string $operator = null, string $value = null): self;

function drop();
public function drop();

function dropIfExists();
public function dropIfExists();

function getSql();
public function getSql();

function execute();
public function execute();
}
4 changes: 2 additions & 2 deletions src/Api/DropInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

interface DropInterface
{
function drop();
public function drop();

function dropIfExists();
public function dropIfExists();
}
44 changes: 22 additions & 22 deletions src/Api/SelectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

interface SelectInterface
{
function distinct(): self;
public function distinct(): self;

function columns(...$columns): self;
public function columns(...$columns): self;

function alias(string $name): self;
public function alias(string $name): self;

function from(string $table_name): self;
public function from(string $table_name): self;

/**
* JOIN table(s) ON condition of
Expand All @@ -22,7 +22,7 @@ function from(string $table_name): self;
*
* @return CodesVault\Howdyqb\Api\SelectInterface
*/
function join($table_name, string $col1 = null, string $col2 = null): self;
public function join($table_name, string $col1 = null, string $col2 = null): self;

/**
* INNER JOIN table(s) ON condition of
Expand All @@ -34,7 +34,7 @@ function join($table_name, string $col1 = null, string $col2 = null): self;
*
* @return CodesVault\Howdyqb\Api\SelectInterface
*/
function innerJoin($table_name, string $col1 = null, string $col2 = null): self;
public function innerJoin($table_name, string $col1 = null, string $col2 = null): self;

/**
* LEFT JOIN table(s) ON condition of
Expand All @@ -46,7 +46,7 @@ function innerJoin($table_name, string $col1 = null, string $col2 = null): self;
*
* @return CodesVault\Howdyqb\Api\SelectInterface
*/
function leftJoin($table_name, string $col1 = null, string $col2 = null): self;
public function leftJoin($table_name, string $col1 = null, string $col2 = null): self;

/**
* RIGHT JOIN table(s) ON condition of
Expand All @@ -58,33 +58,33 @@ function leftJoin($table_name, string $col1 = null, string $col2 = null): self;
*
* @return CodesVault\Howdyqb\Api\SelectInterface
*/
function rightJoin($table_name, string $col1 = null, string $col2 = null): self;
public function rightJoin($table_name, string $col1 = null, string $col2 = null): self;

function where($column, ?string $operator = null, ?string $value = null): self;
public function where($column, ?string $operator = null, ?string $value = null): self;

function andWhere(string $column, ?string $operator, ?string $value): self;
public function andWhere(string $column, ?string $operator, ?string $value): self;

function orWhere(string $column, ?string $operator, ?string $value): self;
public function orWhere(string $column, ?string $operator, ?string $value): self;

function whereNot(string $column, ?string $operator, ?string $value): self;
public function whereNot(string $column, ?string $operator, ?string $value): self;

function andNot(string $column, ?string $operator, ?string $value): self;
public function andNot(string $column, ?string $operator, ?string $value): self;

function whereIn(string $column, ...$value): self;
public function whereIn(string $column, ...$value): self;

function orderBy($column, string $sort): self;
public function orderBy($column, string $sort): self;

function groupBy($column): self;
public function groupBy($column): self;

function limit(int $count): self;
public function limit(int $count): self;

function offset(int $count): self;
public function offset(int $count): self;

function count(string $column, string $alias = ''): self;
public function count(string $column, string $alias = ''): self;

function raw(string $sql): self;
public function raw(string $sql): self;

function getSql();
public function getSql();

function get();
public function get();
}
8 changes: 4 additions & 4 deletions src/Api/UpdateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

interface UpdateInterface
{
function where($column, string $operator = null, string $value = null): self;
public function where($column, string $operator = null, string $value = null): self;

function andWhere(string $column, string $operator = null, string $value = null): self;
public function andWhere(string $column, string $operator = null, string $value = null): self;

function orWhere(string $column, string $operator = null, string $value = null): self;
public function orWhere(string $column, string $operator = null, string $value = null): self;

function getSql();

function execute();
public function execute();
}
5 changes: 5 additions & 0 deletions src/Statement/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function required(): self
return $this;
}

public function nullable(): self
{
return $this->default('NULL');
}

public function primary($columns = []): self
{
if (! empty($columns)) {
Expand Down
25 changes: 21 additions & 4 deletions tests/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

class CreateTest extends TestCase
{
public function testCreateTable()
public function test_create_table()
{
$sql = "CREATE TABLE IF NOT EXISTS wp_test (ID BIGINT(255) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) DEFAULT 'nil', INDEX (ID) )";
$sql = "CREATE TABLE IF NOT EXISTS wp_test (ID BIGINT(255) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) DEFAULT 'nil', INDEX (ID))";

$query =
CreateApi::create('test')
$query = CreateApi::create('test')
->column('ID')->bigInt()->unsigned()->autoIncrement()->primary()->required()
->column('name')->string(255)->required()
->column('email')->string(255)->default('nil')
Expand All @@ -21,4 +20,22 @@ public function testCreateTable()

$this->assertSame($sql, $query);
}

public function test_nullable()
{
$sql = "CREATE TABLE IF NOT EXISTS wp_test (secondary_email VARCHAR(255) DEFAULT 'NULL')";

$query = CreateApi::create('test')
->column('secondary_email')->string(255)->default('NULL')
->getSql();

$this->assertSame($sql, $query);

$query = CreateApi::create('test')
->column('secondary_email')->string(255)->nullable()
->getSql();

$this->assertSame($sql, $query);

}
}

0 comments on commit fd05c4d

Please sign in to comment.