MarwaDB is a PSR-compliant, framework-agnostic, Laravel-style database library built on top of PDO.
It includes a fluent query builder, Eloquent-style ORM, schema builder, migrations, and connection load balancing.
- Multiple Connections with load balancing & retry policies
- Fluent Query Builder — chainable, secure, prepared statements
- Eloquent-style ORM:
- Auto timestamps (
created_at
,updated_at
) - Soft deletes
fillable
/guarded
attributes for mass assignment protection- Relationships:
hasOne
,hasMany
,belongsTo
,belongsToMany
- Eager loading (
with()
,load()
)
- Auto timestamps (
- Schema Builder:
- Create/drop tables
- Foreign keys
- Indexes (
primary
,unique
,index
) - Column modifiers (
nullable
,default
,after
)
- Migrations CLI:
make:migration
migrate
,migrate:rollback
,migrate:refresh
- Seeder Support with Faker
- Debug Panel — view executed queries & timings
- PSR-3 Logging integration
composer require memran/marwa-db
config/database.php
<?php
return [
'default' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => 3306,
'database' => 'app',
'username' => 'root',
'password' => '',
'charset' => 'utf8mb4',
'retry' => 3,
'retry_delay' => 300,
'debug' => true,
],
];
php bin/marwa-db list
Create migration:
php bin/marwa-db make:migration create_users_table
Run migrations:
php bin/marwa-db migrate
Rollback:
php bin/marwa-db migrate:rollback
use Marwa\DB\Facades\DB;
$users = DB::table('users')
->where('status', 'active')
->orderBy('created_at', 'desc')
->limit(5)
->get();
DB::table('users')->insert([
'name' => 'Jane Doe',
'email' => '[email protected]',
]);
use App\Models\User;
// Create record
$user = User::create([
'name' => 'John Doe',
'email' => '[email protected]'
]);
// Find & update
$user = User::find(1);
$user->email = '[email protected]';
$user->save();
// Soft delete
$user->delete();
class User extends Model {
public function posts() {
return $this->hasMany(Post::class);
}
}
class Post extends Model {
public function author() {
return $this->belongsTo(User::class, 'user_id');
}
}
use Marwa\DB\Schema\Schema;
Schema::create('users', function($table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('email')->unique();
$table->timestamps();
});
table($name)
— Selects tableselect(...$columns)
— Selects specific columnswhere($column, $operator, $value)
— Adds WHERE clauseorWhere(...)
— Adds OR WHERE clauseorderBy($column, $direction)
— Sort resultsgroupBy($column)
— Group resultslimit($n)
— Limit rowsget()
— Fetch resultsfirst()
— Fetch first rowinsert($data)
— Insert new record(s)update($data)
— Update record(s)delete()
— Delete record(s)
find($id)
— Find by primary keyall()
— Get all rowscreate($attributes)
— Insert & return modelsave()
— Save changesdelete()
— Delete (with soft delete if enabled)with($relations)
— Eager load relations
create($table, $callback)
— Create new tabledrop($table)
— Drop table- Column types:
string
,integer
,text
,boolean
,timestamp
, etc. - Modifiers:
nullable()
,default($value)
,after($column)
Enable query debug in config:
'debug' => true
View queries:
use Marwa\DB\Support\DebugPanel;
DebugPanel::render();
MIT — See LICENSE for details.