mgx/slimdb

There is no license information available for the latest version (v1.0.1) of this package.

Hafif PDO tabanlı veritabanı bağlantı,migration kütüphanesi

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/mgx/slimdb

v1.0.1 2025-07-29 16:15 UTC

This package is auto-updated.

Last update: 2026-01-11 16:03:22 UTC


README

Hafif, sade ve modern bir PDO tabanlı PHP veritabanı, migration ve seeder kütüphanesi.

Özellikler

  • PDO ile kolay ve güvenli veritabanı bağlantısı
  • Migration desteği (tablo oluşturma, değiştirme, silme)
  • Seeder desteği (örnek veri ekleme)
  • QueryBuilder ile kolay SQL sorguları
  • CLI ile migration ve seeder yönetimi
  • PSR-4 uyumlu modern yapı

Kurulum

Composer ile Kurulum

composer require mgx/slimdb

Not: Henüz Packagist’e yüklemediyseniz, kendi projenizde local olarak kullanmak için:

  1. Ana projenizin composer.json dosyasına aşağıdaki satırı ekleyin:
    "repositories": [
        {
            "type": "path",
            "url": "../mgx-slimdb"
        }
    ]
  2. Sonra:
    composer require mgx/slimdb:dev-main

Temel Kullanım

1. Veritabanı Bağlantısı

use Mgx\Slimdb\Connect;

$config = [
    'host'     => 'localhost',
    'dbname'   => 'test_db',
    'username' => 'root',
    'password' => '',
];

$db = Connect::getInstance($config);

2. Migration Kullanımı

Migration Oluşturma

use Mgx\Slimdb\Migration\Migration;
use Mgx\Slimdb\TableBlueprint;

class CreateUsersTable extends Migration
{
    public function up()
    {
        $this->create('users', function (TableBlueprint $table) {
            $table->id();
            $table->string('name', 100);
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->timestamps();
        });
    }

    public function down()
    {
        $this->drop('users');
    }
}

Migration Çalıştırma (CLI)

php ornekler/Migration_Runner_ornek.php

3. Seeder Kullanımı

Seeder Sınıfı

use Mgx\Slimdb\Seeder;

class UsersSeeder extends Seeder
{
    public function run(): void
    {
        $this->seedTable('users', [
            [
                'name' => 'Admin',
                'email' => 'admin@example.com',
                'password' => password_hash('123456', PASSWORD_DEFAULT)
            ]
        ]);
    }
}

Tüm Seeder'ları Çalıştırmak

php ornekler/DatabaseSeeder.php

4. QueryBuilder Kullanımı

use Mgx\Slimdb\QueryBuilder;

$qb = new QueryBuilder($db);

// Tüm kullanıcıları çek
$users = $qb->table('users')->select()->get();

// Filtreli sorgu
$admins = $qb->table('users')->where('email', 'LIKE', '%admin%')->get();

CLI ile Migration ve Seeder Yönetimi

Hazır CLI dosyası ile migration ve seeder işlemlerini kolayca yönetebilirsiniz:

php ornekler/ornekcli.php migrate      # Tüm migration'ları çalıştırır
php ornekler/ornekcli.php rollback     # Son migration'ı geri alır
php ornekler/ornekcli.php status       # Migration durumunu gösterir
php ornekler/ornekcli.php new <name>   # Yeni migration dosyası oluşturur

Klasör Yapısı

mgx-slimdb/
├── src/                # Ana kütüphane kodları
├── ornekler/           # Kullanım örnekleri ve CLI dosyaları
├── test/               # Otomatik testler
├── migrations/         # Migration dosyaları (kendi projenizde)
├── seeds/              # Seeder dosyaları (kendi projenizde)
├── composer.json
└── README.md

Test

composer install
vendor/bin/phpunit

Katkı ve Lisans

  • Katkı yapmak için PR gönderebilirsiniz.
  • MIT Lisansı ile dağıtılmaktadır.

**Daha fazla örnek ve detay