Laravel MySQLite is meant to be used in conjunction with Laravel. It is a database connection that adds select functions from MySQL to SQLite.
composer require spam-n-eggs/laravel-mysqlite
or alternatively composer require --dev spam-n-eggs/laravel-mysqlite
In order to reduce clutter it is preferable to create a separate Service Provider
If there is a need to conditionally register the Service (i.e. you only use it in testing) create a new class in app/Providers
that extends Mhorninger\SQLite\MySQLiteServiceProvider
<?php
namespace App\Providers;
use Mhorninger\SQLite\MySQLiteServiceProvider as ServiceProvider;
class MySQLiteServiceProvider extends ServiceProvider
{
public function register()
{
if ($shouldRegister) {
parent::register();
}
}
}
Add a line to app/Providers/AppServiceProvider.php
within the register()
method:
$this->app->register(MySQLiteServiceProvider::class);
%U
, %V
, %X
%j
is off by 1 day.MOD(N,M)
and N % M
notation only. N MOD M
is not supported.While this package aims to cover common functionality, there are times when you need support for a function quickly or a custom function that is unique to your application. This is easy to do with two methods from the boot()
method of your service provider class:
<?php
class MySQLiteServiceProvider extends ServiceProvider
{
...
public function boot()
{
$connection = $this->app->get('db')->connection();
if ($connection->getDriverName() === 'sqlite') {
$connection
->addRewriteRule('/CURDATE\(\)/', "date('now')")
->addFunction('CURDATE', fn() => CarbonImmutable::today()->toDateString(), 0);
}
}
}
addRewriteRule()
will replace a string in your query using regex, should Sqlite have a native function that could be used as a 1:1 replacement.addFunction()
uses PDO sqliteCreateFunction()
to register a custom function with PHP in the event that Sqlite doesn't have a drop-in replacement or if logic is more complicated. Read More.Want to file a bug, contribute some code, improve documentation, or request a feature? Awesome Sauce! Read up on our guidelines for contributing. All contributions must follow our Code of Conduct.
Have a question? Log an issue with the Question tag. We'll get back to you in a timely fashion.
This library uses other Open Source components. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source community.
Project: Database https://github.com/illuminate/database Copyright (c) Taylor Otwell License (MIT) https://github.com/laravel/framework/blob/5.7/LICENSE.md
Project: MySQLite https://github.com/Vectorface/MySQLite Copyright (c) 2014 Vectorface, Inc. License: (MIT) https://github.com/Vectorface/MySQLite/blob/master/LICENSE