Skip to content

Commit 6a84608

Browse files
author
Fredrick Peter
committed
Raw Method updated
1 parent 994b867 commit 6a84608

File tree

7 files changed

+177
-89
lines changed

7 files changed

+177
-89
lines changed

README.md

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ env_start([
150150
```
151151

152152
### Direct DB Connection - `Supported but ![Recommended]`
153+
<details><summary>Read more...</summary>
154+
153155
- When initializing the class
154156
- Pass an array as a param to the class
155157
- Why not recommended? Because you must use thesame varaible name `$db` everywhere in your app
@@ -178,7 +180,7 @@ $db->table('users')
178180
->limit(10),
179181
->get();
180182
```
181-
183+
</details>
182184

183185
## More Database Connection Keys
184186
- All available connection keys
@@ -272,6 +274,8 @@ $db->table('users')
272274
- Takes three parameter
273275
- Only the first param is required
274276

277+
<details><summary>Read more...</summary>
278+
275279
| param | Data types |
276280
|-------------------|-----------------|
277281
| column `required` | string |
@@ -320,6 +324,7 @@ $db->table('users')
320324
'status' => 1,
321325
]);
322326
```
327+
</details>
323328

324329
### Decrement
325330
- Same as Increment
@@ -333,6 +338,8 @@ $db->table('users')
333338
```
334339

335340
### Query
341+
<details><summary>Read more...</summary>
342+
336343
- Allows you to use direct `SQL query syntax`
337344

338345
- 1 usage
@@ -350,8 +357,11 @@ $db->get();
350357
-- Query
351358
SELECT count(*) FROM users WHERE status=:status
352359
```
360+
</details>
353361

354362
### Remove Tags
363+
<details><summary>Read more...</summary>
364+
355365
- Helps against `XSS attacks`
356366
- By default we remove-prevention of `XSS attacks` as this should already been handled by Forms Validation before sending into the Database
357367
-> Applies to `insert` `update` `increment` `decrement` methods.
@@ -369,6 +379,7 @@ $db->table('post')
369379
The value should be 'empty' if found as an attack
370380
Now the method automatically apply strict method of cleaning each values
371381
```
382+
</details>
372383

373384
## Fetching Data
374385

@@ -465,16 +476,19 @@ $db->tableExist('users');
465476
|-------------------|-------------------------------------------|
466477
| getAttributes() | `array` Returns an array of data |
467478
| getOriginal() | `object` Returns an object of data |
468-
| isEmpty() | `boolean` `true \| false` If data is empty|
479+
| isEmpty() | `boolean` `true \| false` If data is empty |
469480
| isNotEmpty() | `opposite` of `->isEmpty()` |
470481
| count() | `int` count data in items collection |
471482
| toArray() | `array` Convert items to array |
472483
| toObject() | `object` Convert items to object |
473484
| toJson() | `string` Convert items to json |
474485
| getQuery() | `object` Get Query information |
486+
| toSql() | `string` Sql Query String without execution |
475487

476488

477489
### Collection Usage
490+
<details><summary>Read more...</summary>
491+
478492
- Takes one param as `mixed` data
479493
- Convert data into an array or arrays
480494

@@ -505,7 +519,7 @@ if($users->isNotEmpty()){
505519
}
506520
}
507521
```
508-
522+
</details>
509523

510524
## Pagination
511525
- Configuring Pagination
@@ -662,7 +676,6 @@ SELECT * FROM `tb_wallet`
662676

663677

664678
### Select
665-
<details><summary>Read more...</summary>
666679
- Used to select needed columns from database
667680

668681
```
@@ -677,7 +690,6 @@ SELECT first_name, email
677690
WHERE user_id=:user_id
678691
LIMIT 1
679692
```
680-
</details>
681693

682694

683695
### orderBy
@@ -749,8 +761,6 @@ SELECT *
749761
</details>
750762

751763
### inRandomOrder
752-
<details><summary>Read more...</summary>
753-
754764
```
755765
$db->table('wallet')
756766
->inRandomOrder()
@@ -761,7 +771,6 @@ SELECT *
761771
FROM `wallet`
762772
ORDER BY RAND()
763773
```
764-
</details>
765774

766775
### random
767776
<details><summary>Read more...</summary>
@@ -775,8 +784,6 @@ $db->table('wallet')
775784
</details>
776785

777786
### limit
778-
<details><summary>Read more...</summary>
779-
780787
- Takes one param `$limit` as int. By default value is `1`
781788
```
782789
$db->table('wallet')
@@ -788,7 +795,6 @@ SELECT *
788795
FROM `wallet`
789796
LIMIT 10
790797
```
791-
</details>
792798

793799
### offset
794800
<details><summary>Read more...</summary>
@@ -857,8 +863,6 @@ SELECT *
857863
</details>
858864

859865
### where
860-
<details><summary>Read more...</summary>
861-
862866
- Takes three parameter
863867
- Only the first param is required
864868

@@ -879,7 +883,6 @@ SELECT *
879883
FROM `wallet`
880884
WHERE user_id=:user_id AND amount >: amount AND balance >= : balance
881885
```
882-
</details>
883886

884887
### orWhere
885888
<details><summary>Read more...</summary>
@@ -1038,8 +1041,6 @@ SELECT *
10381041
</details>
10391042

10401043
### groupBy
1041-
<details><summary>Read more...</summary>
1042-
10431044
- Takes one param `$column`
10441045
```
10451046
$db->table('wallet')
@@ -1052,7 +1053,6 @@ SELECT *
10521053
FROM `wallet`
10531054
WHERE user_id=:user_id GROUP BY amount
10541055
```
1055-
</details>
10561056

10571057
## Database Migration
10581058
- Similar to Laravel DB Migration `Just to make database table creation more easier`
@@ -1116,10 +1116,10 @@ Migration::run('column', 'column_name);
11161116
```
11171117

11181118

1119-
## Optimize-table
1119+
## Optimize-table
11201120
- Database table optimization
11211121

1122-
1122+
<details><summary>Read more...</summary>
11231123
### Optimize
11241124
- Optimize Multiple Tables
11251125
- Takes a param as an `array` table_name
@@ -1128,22 +1128,29 @@ Migration::run('column', 'column_name);
11281128
```
11291129
$db->optimize(['tb_wallet', 'tb_user']);
11301130
```
1131+
</details>
11311132

11321133
### Analize
1134+
<details><summary>Read more...</summary>
1135+
11331136
- Analize Single Table
11341137
- Takes a param as an `string` table_name
11351138

11361139
```
11371140
$db->analize('tb_wallet');
11381141
```
1142+
</details>
11391143

11401144
### Repair
1145+
<details><summary>Read more...</summary>
1146+
11411147
- Repair Single Table
11421148
- Takes a param as an `string` table_name
11431149

11441150
```
11451151
$db->repair('tb_wallet');
11461152
```
1153+
</details>
11471154

11481155
## Get Database Query
11491156

@@ -1165,6 +1172,8 @@ $db->repair('tb_wallet');
11651172
| $db->getConnection() | get_connection() |
11661173

11671174
## Database Import
1175+
<details><summary>Read more...</summary>
1176+
11681177
- You can use this class to import .sql into a database programatically
11691178

11701179
```
@@ -1175,14 +1184,16 @@ $import = new DBImport();
11751184
// needs absolute path to database file
11761185
$response = $import->DatabaseImport('orm.sql');
11771186
1178-
11791187
- Status code
11801188
->response == 404 (Failed to read file or File does'nt exists
11811189
->response == 400 (Query to database error
11821190
->response == 200 (Success importing to database
11831191
```
1192+
</details>
11841193

11851194
## Update Env Variable
1195+
<details><summary>Read more...</summary>
1196+
11861197
- You can use this class to import .sql into a database programatically
11871198

11881199
| Params | Description |
@@ -1202,6 +1213,7 @@ OrmDotEnv::updateENV('DB_CHARSET', 'utf8', false);
12021213
Returns - Boolean
12031214
true|false
12041215
```
1216+
</details>
12051217

12061218
## Collation And Charset
12071219
- Collation and Charset Data `listing`
@@ -1224,6 +1236,8 @@ true|false
12241236
- You can as well extends the DB class and use along
12251237
- If inherited class must use a __construct, Then you must use `parent::__construct();`
12261238

1239+
<details><summary>Read more...</summary>
1240+
12271241
```
12281242
use builder\Database\DB;
12291243
@@ -1243,6 +1257,7 @@ class PostClass extends DB{
12431257
}
12441258
}
12451259
```
1260+
<details>
12461261

12471262
## Helpers
12481263

src/Capsule/Manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Exception;
88
use builder\Database\DB;
99
use builder\Database\Constants;
10+
use builder\Database\Query\Builder;
1011

1112

1213
class Manager extends Constants{

src/Migrations/Schema.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static public function dropTable(?string $tableName)
5454
// Handle query
5555
try{
5656
// DROP TABLE IF EXISTS
57-
self::$db->raw( "DROP TABLE {$tableName};" )->execute();
57+
self::$db->query( "DROP TABLE {$tableName};" )->execute();
5858

5959
echo "Table `{$tableName}` dropped successfully <br> \n";
6060
} catch (PDOException $e){
@@ -89,13 +89,13 @@ static public function dropColumn(?string $tableName, ?string $columnName)
8989
// Handle query
9090
try{
9191
// DROP COLUMN IF EXISTS
92-
self::$db->raw( "ALTER TABLE {$tableName} DROP COLUMN {$columnName};" )->execute();
92+
self::$db->query( "ALTER TABLE {$tableName} DROP COLUMN {$columnName};" )->execute();
9393

9494
// DROP COLUMN TRIGGERS
95-
self::$db->raw( "DROP TRIGGER IF EXISTS {$columnName}_created_at;" )->execute();
95+
self::$db->query( "DROP TRIGGER IF EXISTS {$columnName}_created_at;" )->execute();
9696

9797
// DROP COLUMN TRIGGERS
98-
self::$db->raw( "DROP TRIGGER IF EXISTS {$columnName}_updated_at;" )->execute();
98+
self::$db->query( "DROP TRIGGER IF EXISTS {$columnName}_updated_at;" )->execute();
9999

100100
echo "Column `{$columnName}` on `{$tableName}` dropped successfully <br> \n";
101101
} catch (PDOException $e){

0 commit comments

Comments
 (0)