spam-n-eggs/laravel-mysqlite
Composer 安装命令:
composer require 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.
README 文档
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.
Requirements
- PHP: >= 8.2
- Laravel: 12.x or 13.x (
illuminate/database ^12.0 || ^13.0)
For users upgrading from v1.x, see UPGRADING.md for migration instructions.
Usage
Adding the Composer Resource
- Execute
composer require spam-n-eggs/laravel-mysqliteor 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/Providersthat 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.phpwithin 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:
%jis 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 % Mnotation only.N MOD Mis 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.
Support This Project
laravel-mysqlite is maintained by Dominion Solutions as open-source work. If this package saves you time, consider hiring us for your next project.
We offer full-stack software engineering services — from feature development and architecture to debugging and performance optimization. Whether you need a long-term development partner or a focused engagement, we'd love to help.
StackLift is our Laravel upgrade and stabilization engagement. We upgrade your framework, audit dependencies, resolve breaking changes, and hand you a maintainable codebase — starting at $1.5k.
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
spam-n-eggs/laravel-mysqlite 适用场景与选型建议
spam-n-eggs/laravel-mysqlite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.7k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2019 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 spam-n-eggs/laravel-mysqlite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spam-n-eggs/laravel-mysqlite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-24