Skip to content

Commit

Permalink
Composer version release
Browse files Browse the repository at this point in the history
  • Loading branch information
whizsid committed Jun 5, 2019
1 parent dbccc29 commit 5fecb7b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 30 deletions.
60 changes: 53 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)

A fully featured SQL like engine for php arrays. You can do join,group,order, get sum and many more sql functions to PHP arrays with AB.
Runtime SQL like query lanaguage for manipulate php arrays. written in pure php and not using any sql engine. Note:- this is not an any king of query builder.

## Basic

Expand Down Expand Up @@ -35,13 +35,20 @@ $ab->createTable('customers',function(Table $tbl){
});
```

### Simple Select query
Or with data array.

```
$query = $ab->query();
$ab->createTable('tbl_another',[
[
'c_id'=>1,
'ant_id'=>"A"
],
[
'c_id'=>2,
'ant_id'=>"B"
]
]);
$results = $query->select('table_name','column_1','column_2')->execute();
```

### Join Clause
Expand Down Expand Up @@ -71,9 +78,48 @@ $select->limit(10,20);
```
$select->orderBy($query->cus->c_name)->orderBy($query->cus->c_address,"desc");
```
## Contribute

Currently I haven't an extra time to develop this. Email me on rameshkithsirihettiarachchi@gmail.com if you like to contribute this project.
### Select query

```
$selectQuery = $ab->query()->select(
$ab->tbl_customer,
$ab::groupConcat(AB_DISTINCT,$ab->tbl_facility->fac_code)->as('new_sum'),
$ab->tbl_customer->c_id,
$ab->tbl_another->ant_id,
$ab->tbl_facility->fac_code
);
$selectQuery->join('inner',$ab->tbl_facility)->on($ab->tbl_customer->c_id,'=',$ab->tbl_facility->c_id);
$selectQuery->join('inner',$ab->tbl_another)->on($ab->tbl_customer->c_id,'=',$ab->tbl_another->c_id);
$selectQuery->orderBy($ab->tbl_customer->c_id,'desc');
$selectQuery->groupBy($ab->tbl_another->ant_id);
$selectQuery->where($ab->tbl_another->ant_id,'=',"A");
$selectQuery->limit(1);
$result = $selectQuery->execute()->fetchAssoc();
```

### Update Query

```
$updateQuery = $ab->query()->update($ab->tbl_customer)->set($ab->tbl_customer->c_name,'Updated name');
$updateQuery->where($ab->tbl_another->ant_id,"B");
$updateQuery->join(AB_JOIN_INNER,$ab->tbl_another)->on($ab->tbl_another->c_id,'=',$ab->tbl_customer->c_id);
$updateQuery->limit(1);
$updateQuery->execute();
```

### Delete query

```
$deleteQuery = $ab->query()->delete($ab->tbl_customer);
$deleteQuery->where($ab->tbl_another->ant_id,"B");
$deleteQuery->join(AB_JOIN_INNER,$ab->tbl_another)->on($ab->tbl_another->c_id,'=',$ab->tbl_customer->c_id);
$deleteQuery->limit(1);
$deleteQuery->execute();
```

All Examples in the `example/index.php` file.

## Goals

Expand Down
18 changes: 11 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "whizsid/array-base",
"description": "Make a temporaray database for your application with ArrayBase",
"type": "library",
"name": "whizsid/arraybase",
"description": "Pure PHP runtime SQL like query language for manipulate php array data.",
"type": "library",
"keywords":[
"sql","join","group","order","php","array","left","inner","right","outer","select","update","collection"
],
"license": "MIT",
"authors": [
{
"name": "Ramesh Kithsiri HettiArachchi",
"email": "rameshkithsirihettiarachchi@gmail.com"
"name": "WhizSid",
"email": "whizsid@aol.com"
}
],
"minimum-stability": "dev",
Expand All @@ -21,10 +24,11 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"WhizSid\\ArrayBase\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "7"
}
},
"version":"0.0.1"
}
30 changes: 15 additions & 15 deletions example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@
'ant_id'=>"B"]
]);

// $selectQuery = $ab->query()->select(
// $ab->tbl_customer,
// $ab::groupConcat(AB_DISTINCT,$ab->tbl_facility->fac_code)->as('new_sum'),
// $ab->tbl_customer->c_id,
// $ab->tbl_another->ant_id,
// $ab->tbl_facility->fac_code
// );

// $selectQuery->join('inner',$ab->tbl_facility)->on($ab->tbl_customer->c_id,'=',$ab->tbl_facility->c_id);
// $selectQuery->join('inner',$ab->tbl_another)->on($ab->tbl_customer->c_id,'=',$ab->tbl_another->c_id);
// $selectQuery->orderBy($ab->tbl_customer->c_id,'desc');
// $selectQuery->groupBy($ab->tbl_another->ant_id);
// $selectQuery->where($ab->tbl_another->ant_id,'=',"A");
// $selectQuery->limit(1);
// $result = $selectQuery->execute()->fetchAssoc();
$selectQuery = $ab->query()->select(
$ab->tbl_customer,
$ab::groupConcat(AB_DISTINCT,$ab->tbl_facility->fac_code)->as('new_sum'),
$ab->tbl_customer->c_id,
$ab->tbl_another->ant_id,
$ab->tbl_facility->fac_code
);

$selectQuery->join(AB_JOIN_INNER,$ab->tbl_facility)->on($ab->tbl_customer->c_id,'=',$ab->tbl_facility->c_id);
$selectQuery->join(AB_JOIN_INNER,$ab->tbl_another)->on($ab->tbl_customer->c_id,'=',$ab->tbl_another->c_id);
$selectQuery->orderBy($ab->tbl_customer->c_id,'desc');
$selectQuery->groupBy($ab->tbl_another->ant_id);
$selectQuery->where($ab->tbl_another->ant_id,'=',"A");
$selectQuery->limit(1);
$result = $selectQuery->execute()->fetchAssoc();

$updateQuery = $ab->query()->update($ab->tbl_customer)->set($ab->tbl_customer->c_name,'Updated name');
$updateQuery->where($ab->tbl_another->ant_id,"B");
Expand Down
2 changes: 1 addition & 1 deletion tests/ABTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Tests;
namespace WhizSid\ArrayBase\Tests;

use PHPUnit\Framework\TestCase;
use WhizSid\ArrayBase\AB;
Expand Down
Empty file added tests/HelperTest.php
Empty file.

0 comments on commit 5fecb7b

Please sign in to comment.