spam-n-eggs / laravel-mysqlite
MySQLite is a Laravel connector for SQLite that emulates MySQL functionality. The currently ported functionalities can be viewed in README.md on the github site.
Fund package maintenance!
spam-n-eggs
paypal.me/DominionSolutionsLLC
Installs: 5 092
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 6
Open Issues: 13
Requires
- php: >=7.3.0
- illuminate/database: ^7.0 || ^8.0
- vectorface/mysqlite: ^0.1.4
Requires (Dev)
- codedungeon/phpunit-result-printer: dev-master
- php-coveralls/php-coveralls: ^2.4
- phpmd/phpmd: ^2.6
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.4
Suggests
- ext-intl: For locales other than en
- symfony/intl: If you just need the en locale
- dev-master
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- 0.2.0
- 0.1.2
- 0.1.1
- v0.1.0
- v0.0.1
- dev-dependabot/composer/guzzlehttp/guzzle-7.7.x-dev
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/phpmd/phpmd-2.10.2
- dev-CU-mryuk7_Laravel-MySQLite-Packagistorg-is-complaining-that-the-composerjson-is-corrupt_Ethan-Sowell
- dev-dependabot/composer/php-coveralls/php-coveralls-2.4.3
- dev-5.5-LTS
- dev-scrutinizer-patch-1
- dev-versioning
This package is auto-updated.
Last update: 2024-11-21 03:37:02 UTC
README
Laravel MySQLite is meant to be used in conjunction with Laravel. It is a database connection that adds select functions from MySQL to SQLite.
Usage
Adding the Composer Resource
- Execute
composer require spam-n-eggs/laravel-mysqlite
or alternativelycomposer require --dev spam-n-eggs/laravel-mysqlite
Registering as a Service Provider
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 extendsMhorninger\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 theregister()
method:$this->app->register(MySQLiteServiceProvider::class);
Ported Functionality
Constants
Operators
Methods
Aggregate
Date and Time
- convert_tz(date, fromTimezone, toTimezone)
- date_add(date, INTERVAL <number_of> <interval_specifier>)
- Ported Interval Specifiers
- SECOND
- MINUTE
- HOUR
- DAY
- WEEK
- MONTH
- YEAR
- Differences
- All DATE_ADD calls bring back the entire date time as opposed to just the short date.
- Ported Interval Specifiers
- date_format(date, format)
- Un-ported Format Strings:
%U
,%V
,%X
- Other Limitations:
%j
is off by 1 day.
- Un-ported Format Strings:
- hour(time)
- minute(time)
- now()
- timestampdiff(timeUnit, startTimeStamp, endTimeStamp)
- time_to_sec(timeExpression)
- timediff(timeExpression1, timeExpression2)
- to_days(date)
- unix_timestamp(date = null)
- utc_timestamp()
- weekday(date)
Flow
Numeric
- mod(number, divisor)
- Limitations - Support for Standard
MOD(N,M)
andN % M
notation only.N MOD M
is not supported.
- Limitations - Support for Standard
- rand()
- sqrt(value)
String
- concat(string ...)
- concat_ws(separator, string ...)
- format(number, decimals, locale = 'en_US')
- lpad(string, length, pad)
- rpad(string, length, pad)
- left(string, length)
- right(string, length)
Miscellaneous
Vectorface-Specific
Comparison
Custom Functionality
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 PDOsqliteCreateFunction()
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.
Contributing
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.
Questions
Have a question? Log an issue with the Question tag. We'll get back to you in a timely fashion.
Credits
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