Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dominion-solutions/laravel-mysqlite

A Laravel Service Provider that injects select MySQL functions into SQLite
https://github.com/dominion-solutions/laravel-mysqlite

composer database-adapter database-connector laravel laravel-mysqlite laravel-package laravel5 laravel6 mysql mysql-database mysqlite php sqlite sqlite-database sqlite3 sqlitedatabase vectorface

Last synced: 3 months ago
JSON representation

A Laravel Service Provider that injects select MySQL functions into SQLite

Awesome Lists containing this project

README

        

# laravel-mysqlite
[![Build Status](https://travis-ci.org/spam-n-eggs/laravel-mysqlite.svg?branch=master)](https://travis-ci.org/spam-n-eggs/laravel-mysqlite)
[![Coverage Status](https://coveralls.io/repos/github/spam-n-eggs/laravel-mysqlite/badge.svg?branch=master)](https://coveralls.io/github/spam-n-eggs/laravel-mysqlite?branch=master)
[![StyleCI](https://github.styleci.io/repos/167069269/shield?branch=master)](https://github.styleci.io/repos/167069269)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spam-n-eggs/laravel-mysqlite/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spam-n-eggs/laravel-mysqlite/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/spam-n-eggs/laravel-mysqlite/v/stable)](https://packagist.org/packages/spam-n-eggs/laravel-mysqlite)
[![Total Downloads](https://poser.pugx.org/spam-n-eggs/laravel-mysqlite/downloads)](https://packagist.org/packages/spam-n-eggs/laravel-mysqlite)
[![License](https://poser.pugx.org/spam-n-eggs/laravel-mysqlite/license)](https://packagist.org/packages/spam-n-eggs/laravel-mysqlite)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=spam-n-eggs/laravel-mysqlite)](https://dependabot.com)

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
1. Execute `composer require spam-n-eggs/laravel-mysqlite` or alternatively `composer 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
1. 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
app->register(MySQLiteServiceProvider::class);
```
# Ported Functionality
## Constants
- [UTC_TIMESTAMP][utc_timestamp]
## Operators
- [DIV](https://dev.mysql.com/doc/refman/8.0/en/arithmetic-functions.html#operator_div)
## Methods
### Aggregate
- [bit_or (int ...)](https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_bit-or)
### Date and Time
- [convert_tz(date, fromTimezone, toTimezone)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_convert-tz)
- [date_add(date, INTERVAL )]()
- 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.
- [date_format(date, format)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format)
- Un-ported Format Strings: `%U`, `%V`, `%X`
- Other Limitations: `%j` is off by 1 day.
- [hour(time)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_hour)
- [minute(time)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_minute)
- [now()](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_now)
- [timestampdiff(timeUnit, startTimeStamp, endTimeStamp)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timestampdiff)
- [time_to_sec(timeExpression)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_time-to-sec)
- [timediff(timeExpression1, timeExpression2)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timediff)
- [to_days(date)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_to-days)
- [unix_timestamp(date = null)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_unix-timestamp)
- [utc_timestamp()][utc_timestamp]
- [weekday(date)](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_weekday)
### Flow
- [if(condition, onTrue, onFalse)](https://dev.mysql.com/doc/refman/8.0/en/control-flow-functions.html#function_if)
### Numeric
- [mod(number, divisor)](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_mod)
- Limitations - Support for Standard `MOD(N,M)` and `N % M` notation only. `N MOD M` is not supported.
- [rand()](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_rand)
- [sqrt(value)](https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_sqrt)
### String
- [concat(string ...)](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat)
- [concat_ws(separator, string ...)](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat-ws)
- [format(number, decimals, locale = 'en_US')](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_format)
- [lpad(string, length, pad)](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lpad)
- [rpad(string, length, pad)](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_rpad)
- [left(string, length)](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_left)
- [right(string, length)](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_right)
### Miscellaneous
- [inet_ntoa(ipAddress)](https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_inet-ntoa)
### Vectorface-Specific
#### Comparison
- [least(mixed ...)](https://github.com/Vectorface/MySQLite/blob/master/src/Vectorface/MySQLite/MySQL/Comparison.php)

# 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
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][sqlitecreatefunction].

# Contributing
Want to file a bug, contribute some code, improve documentation, or request a feature? Awesome Sauce! Read up on our guidelines for [contributing][contributing]. All contributions must follow our [Code of Conduct][codeofconduct].

# Questions
Have a question? [Log an issue][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

[utc_timestamp]: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_utc-timestamp
[contributing]: ./.github/contributing.md
[issue]: https://github.com/spam-n-eggs/laravel-mysqlite/issues
[codeofconduct]:./.github/CODE_OF_CONDUCT.md
[sqlitecreatefunction]: https://www.php.net/manual/en/pdo.sqlitecreatefunction.php