Convert Figma logo to code with AI

illuminate logodatabase

[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

2,675
596
2,675
0

Top Related Projects

9,433

Doctrine Database Abstraction Layer

4,825

The lightweight PHP database framework to accelerate the development.

2,007

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.

Quick Overview

Illuminate/database is a powerful database toolkit for PHP, part of the Laravel framework. It provides an expressive query builder, ActiveRecord style ORM, and schema builder, supporting various database systems including MySQL, PostgreSQL, SQLite, and SQL Server.

Pros

  • Eloquent ORM for intuitive and expressive database interactions
  • Fluent query builder for complex queries without writing raw SQL
  • Database migrations for version control of database schema
  • Support for multiple database connections and types

Cons

  • Learning curve for developers new to Laravel ecosystem
  • Performance overhead compared to raw SQL queries in some cases
  • Potential for overuse of eager loading, leading to N+1 query problems
  • Limited support for some advanced database features specific to certain systems

Code Examples

  1. Basic query using Query Builder:
$users = DB::table('users')
            ->where('active', 1)
            ->orderBy('name', 'desc')
            ->get();
  1. Eloquent ORM relationship example:
class User extends Model
{
    public function posts()
    {
        return $this->hasMany(Post::class);
    }
}

$user = User::find(1);
$posts = $user->posts;
  1. Database migration example:
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});

Getting Started

  1. Install via Composer:
composer require illuminate/database
  1. Set up database configuration:
use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
    'driver' => 'mysql',
    'host' => 'localhost',
    'database' => 'database',
    'username' => 'root',
    'password' => 'password',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
]);

$capsule->setAsGlobal();
$capsule->bootEloquent();
  1. Start using the Query Builder or Eloquent ORM in your application.

Competitor Comparisons

9,433

Doctrine Database Abstraction Layer

Pros of DBAL

  • More database-agnostic, supporting a wider range of database systems
  • Offers lower-level database abstraction, providing more fine-grained control
  • Standalone library, can be used independently of a full ORM or framework

Cons of DBAL

  • Steeper learning curve compared to Database's more intuitive API
  • Less integration with Laravel ecosystem and features
  • Fewer high-level abstractions for common tasks

Code Comparison

DBAL:

$queryBuilder = $conn->createQueryBuilder();
$queryBuilder
    ->select('id', 'name')
    ->from('users')
    ->where('active = ?')
    ->setParameter(0, 1);
$result = $queryBuilder->executeQuery();

Database:

$users = DB::table('users')
    ->select('id', 'name')
    ->where('active', 1)
    ->get();

Summary

DBAL offers more flexibility and database support but requires more setup and knowledge. Database provides a simpler, more intuitive API that integrates seamlessly with Laravel. DBAL is better suited for complex, database-agnostic projects, while Database excels in Laravel-based applications with its elegant syntax and framework integration.

4,825

The lightweight PHP database framework to accelerate the development.

Pros of Medoo

  • Lightweight and simple, with a smaller footprint than Database
  • Easy to set up and use, requiring minimal configuration
  • Supports multiple database types out of the box (MySQL, MSSQL, SQLite, etc.)

Cons of Medoo

  • Less feature-rich compared to Database, with fewer advanced querying options
  • Limited support for complex relationships and advanced ORM features
  • Smaller community and ecosystem compared to Database

Code Comparison

Medoo query example:

$data = $database->select("users", [
    "name",
    "email"
], [
    "age[>]" => 18
]);

Database query example:

$users = DB::table('users')
    ->select('name', 'email')
    ->where('age', '>', 18)
    ->get();

Both libraries offer simple query syntax, but Database provides a more fluent interface and additional methods for complex queries. Medoo focuses on simplicity and ease of use, while Database offers more advanced features and better integration with the Laravel ecosystem.

Medoo is ideal for smaller projects or when working outside of Laravel, while Database shines in larger, more complex applications, especially within the Laravel framework. The choice between the two depends on project requirements, scalability needs, and the developer's familiarity with Laravel conventions.

2,007

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.

Pros of idiorm

  • Lightweight and simple to use, with a minimal learning curve
  • No dependencies, making it easy to integrate into existing projects
  • Supports multiple database types out of the box

Cons of idiorm

  • Limited advanced features compared to more robust ORMs
  • Less active development and community support
  • Lacks built-in migration and seeding capabilities

Code Comparison

idiorm:

$user = ORM::for_table('users')->find_one(1);
$user->name = 'John Doe';
$user->save();

illuminate/database:

$user = User::find(1);
$user->name = 'John Doe';
$user->save();

Summary

idiorm is a lightweight ORM that offers simplicity and ease of use, making it suitable for small to medium-sized projects. It has no dependencies and supports multiple database types out of the box. However, it lacks advanced features and has less active development compared to illuminate/database.

illuminate/database, part of the Laravel framework, provides a more robust and feature-rich ORM experience. It offers advanced querying capabilities, migrations, and strong community support. While it has a steeper learning curve, it's better suited for larger, more complex applications that require scalability and extensive database interactions.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Illuminate Database

The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style ORM, and schema builder. It currently supports MySQL, Postgres, SQL Server, and SQLite. It also serves as the database layer of the Laravel PHP framework.

Usage Instructions

First, create a new "Capsule" manager instance. Capsule aims to make configuring the library for usage outside of the Laravel framework as easy as possible.

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
    'driver' => 'mysql',
    'host' => 'localhost',
    'database' => 'database',
    'username' => 'root',
    'password' => 'password',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
]);

// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();

composer require "illuminate/events" required when you need to use observers with Eloquent.

Once the Capsule instance has been registered. You may use it like so:

Using The Query Builder

$users = Capsule::table('users')->where('votes', '>', 100)->get();

Other core methods may be accessed directly from the Capsule in the same manner as from the DB facade:

$results = Capsule::select('select * from users where id = ?', [1]);

Using The Schema Builder

Capsule::schema()->create('users', function ($table) {
    $table->increments('id');
    $table->string('email')->unique();
    $table->timestamps();
});

Using The Eloquent ORM

class User extends Illuminate\Database\Eloquent\Model {}

$users = User::where('votes', '>', 1)->get();

For further documentation on using the various database facilities this library provides, consult the Laravel framework documentation.