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

Related tags

Database database
Overview

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.

Comments
  • Added $unfillable array in model

    Added $unfillable array in model

    Allows specifying items that are 'unfillable' via mass assignment. Handy when there are many attributes and only a couple that are not fillable. Suggested by someone on #laravel.

    opened by jwalton512 9
  • Eloquent models can easily call increment and decrement.

    Eloquent models can easily call increment and decrement.

    If you have an existing model object you can't call increment or decrement on it without setting the wheres() manually.

    You can now do:

    $user = User::find(1);
    
    $user->increment('posts', 1);
    

    Signed-off-by: Jason Lewis [email protected]

    opened by jasonlewis 7
  • Change the Builder->take() funtion to consider zero value as return with no limit

    Change the Builder->take() funtion to consider zero value as return with no limit

    In many situations, when using Eloquent objects, we create a function to retrieve a Collection of objects based on a specific filter. Example:

    public function getUsersByName ($name, $limit = 0) { return User::where('name', 'like', '%'.$name'%')->take($limit)->get(); }

    In this kind of functions we want to limit the collection when some limit is specified and retrieve all objects when no limit is specified. To accomplish this we change the take function in order to consider the value 0 as to retrieve all the founded objects. Without this change we have always to implement the previous function like this:

    public function getUsersByName ($name, $limit = 0) { if ($limit = 0) { return User::where('name', 'like', '%'.$name'%')->get(); } else { return User::where('name', 'like', '%'.$name'%')->take($limit)->get(); } }

    opened by miguelbgouveia 5
  • Applying getMutators to collection before output as array or json string

    Applying getMutators to collection before output as array or json string

    When returning a Eloquent Collection, I noticed the getMutator is not applied to the resulting array and thought, it will make it better to apply getMutator method to the each result before the collection is fully converted to an array or json string.

    opened by raftalks 4
  • Limited morph properties by type

    Limited morph properties by type

    This is a functionality to allow a query like "morphWith" but named "morphProperties" to limit the properties of morph by type.

    $recommendations = Recommendation::with(['recommendable' => function (MorphTo $morphTo) {
        // This limit the properties showed for morph type
        $morphTo->morphProperties([
            User::class => ['id', 'username'],
            UserVacantion::class => ['id', 'user_id'],
        ]);
    
        // This eager load some relationships for morph type
        $morphTo->morphWith([
            User::class => [],
            UserVacantion::class => ['user:id,username'],
        ]);
    }])->get();
    
    opened by ioan-cristea 3
  • Move morph relation morph type to first place in query

    Move morph relation morph type to first place in query

    As discussed here: https://github.com/laravel/framework/issues/26720 Proposal to move entity name to first place in query builder. This would fit current migration index design.

    opened by therezor 3
  • Added Comment Modifier to Mysql Grammar

    Added Comment Modifier to Mysql Grammar

    Hi Taylor,

    Love your work Laravel is just awesome!!

    I really care about documentation and always find my adding comments in the comments column in mysql

    Till now I would do something like this

    Schema::create('users', function($table) {
                $table->integer('extranet_id')->nullable()
            });
    
    DB::update("ALTER TABLE `users` CHANGE `extranet_id` `extranet_id` INT(255)  COMMENT 'Comment about the field here!'");
    

    This seems like double work.

    So I have created a fork and added this functionality, please review and merge if all ok.

    Now you can do something like this.

    Schema::create('users', function($table) {
                $table->integer('extranet_id')->nullable()->comment('Comment about the field here!');
            });
    

    I also created a test but cant seem to find where to put it. There is no tests folder or repo?

    Here is the test

        public function testAddingComment()
        {
            $blueprint = new Blueprint('users');
            $blueprint->string('foo')->comment('foo');
            $statements = $blueprint->toSql($this->getGrammar());
    
            $this->assertEquals(1, count($statements));
            $this->assertEquals("alter table `users` add `foo` varchar(255) not null comment 'foo'", $statements[0]);
        }
    

    Lastly I will also update the documentation when you merge the change.

    Sorry I didn't update the other grammars as I not familiar with their syntax.

    opened by garethhallnz 3
  • Fixing bugs related to setting DateTime attributes

    Fixing bugs related to setting DateTime attributes

    Fixing:  - https://github.com/illuminate/database/commit/be7246d44f4667e27a196cbf91225f758b862004#L0R906  - https://github.com/illuminate/database/commit/be7246d44f4667e27a196cbf91225f758b862004#L0R916  - https://github.com/illuminate/database/commit/be7246d44f4667e27a196cbf91225f758b862004#L0R919

    opened by bencorlett 3
  • Change

    Change "bigint" to "integer" in Postgres schema grammar.

    Bigint has too big a range to be returned as an int in PHP. It is returned as a string, which can be confusing when expecting an int to be returned. In addition, the range of integer is suitable for most cases: -2147483648 to +2147483647.

    opened by conradkleinespel 3
  • Collection::contains()

    Collection::contains()

    This rather large pull request implements a contains() method for the collection class.

    That method checks whether an element with the given primary key (ID) is part of the collection. To make this simpler, I made sure that every item in the collection is indexed by the ID. That makes up the largest part of this pull request (along with modifying the unit tests appropriately).

    Example

    What does that allow us to do?

    For example, if you have a user with a bunch of associated rules, it allows you to easily check whether your user is associated with the rule with ID 5 like this:

    if ($user->roles->contains(1))
    {
        // do something...
    }
    

    Notes & questions for Taylor

    I am, let's say, 90-percent sure that this implementation is fine (tested, after all). I doubt there is a central place where this could be done, except for the collection constructor maybe, but I didn't want to add any ugly instanceof-like code (meta programming etc.). I usually found a place to set the keys in a place where the arrays were being assembled anyway, because I tried to avoid having to iterate over all the elements just for this purpose.

    Also, about testing: the feature is basically implicitly tested in the existing tests now because they rely on certain IDs being returned as keys, but I wonder whether I should add methods testing explicitly this...

    opened by franzliedke 3
  • Returning proper value from isGuarded()

    Returning proper value from isGuarded()

    isGuardable() returns false for columns that are not guardable. So the "!" sign should be removed from the return statement of isGuarded() function before isGuardable(). Otherwise normal attributes which are to be Posted to the database gets guarded and causes problems.

    opened by saptarshi539 2
Owner
The Laravel Components
The Laravel Components
Read and write CSV files with PHP.

Read and write CSV files with PHP. This package provides a minimalistic wrapper around the excellent league/csv package. The API is heavily inspired b

Ryan Chandler 6 Nov 16, 2022
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.

Please give it a Star if you like the project ?? ❤️ SleekDB - A NoSQL Database made using PHP Full documentation: https://sleekdb.github.io/ SleekDB i

Kazi Mehedi Hasan 745 Jan 7, 2023
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

SleekwareDB 12 Dec 11, 2022
Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

Yan Ivanov 441 Dec 11, 2022
The lightweight PHP database framework to accelerate development

The lightweight PHP database framework to accelerate development Features Lightweight - Less than 100 KB, portable with only one file Easy - Extremely

Angel Lai 4.6k Dec 28, 2022
A complete, simple and powerful database framework written in PHP

BaseSQL BaseSQL is a complete database framework written in PHP. It was built to accelerate projects development by handle database connections and qu

Willian Pinheiro 2 Sep 21, 2021
Phpstan-dba - database handling related class reflection extension for PHPStan & framework-specific rules

database handling class reflection extension for PHPStan This extension provides following features: PDO->query knows the array shape of the returned

Markus Staab 175 Dec 29, 2022
The fastest pure PHP database framework with a powerful static code generator, supports horizontal scale up, designed for PHP7

Maghead 4.0.x IS CURRENTLY UNDER HEAVY DEVELOPMENT, API IS NOT STABLE Maghead is an open-source Object-Relational Mapping (ORM) designed for PHP7. Mag

Maghead 477 Dec 24, 2022
This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FTP, SFTP, and Rackspace Cloud

Database Backup Manager This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FT

Backup Manager 1.6k Dec 23, 2022
The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

Mark Armendariz 0 Jan 7, 2022
Builds Cycle ORM schemas from OpenAPI 3 component schemas

Phanua OpenAPI 3 + Jane + Cycle ORM = ?? Phanua builds Cycle ORM schemas from OpenAPI 3 component schemas. Released under the MIT License. WARNING: Th

Matthew Turland 5 Dec 26, 2022
Process - The Process component executes commands in sub-processes.

Process Component The Process component executes commands in sub-processes. Sponsor The Process component for Symfony 5.4/6.0 is backed by SensioLabs.

Symfony 7.1k Dec 29, 2022
Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.

Laravel Thermite Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster. ?? Supporting If you are usin

Renoki Co. 9 Nov 15, 2022
A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.

Eloquence Eloquence is a package to extend Laravel's base Eloquent models and functionality. It provides a number of utilities and classes to work wit

Kirk Bushell 470 Dec 8, 2022
Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.

Laravel Migrations Generator Generate Laravel Migrations from an existing database, including indexes and foreign keys! Upgrading to Laravel 5.4 Pleas

Bernhard Breytenbach 3.3k Dec 30, 2022
[Package] Multi-tenant Database Schema Manager for Laravel

Multi-tenant Database Schema Manager for Laravel Tenanti allow you to manage multi-tenant data schema and migration manager for your Laravel applicati

Orchestra Platform 580 Dec 5, 2022
Laravel 5 - Repositories to abstract the database layer

Laravel 5 Repositories Laravel 5 Repositories is used to abstract the data layer, making our application more flexible to maintain. See versions: 1.0.

Anderson Andrade 4k Jan 6, 2023
A Redis based, fully automated and scalable database cache layer for Laravel

Lada Cache A Redis based, fully automated and scalable database cache layer for Laravel Contributors wanted! Have a look at the open issues and send m

Matt 501 Dec 30, 2022
Adminer database management tool for your Laravel application.

Laravel Adminer Adminer database management tool for your Laravel application. Table of Contents Introduction Features Installation CSRF token middlew

Khalid Moharrum 45 Jul 25, 2022