Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/renoki-co/l1
Extend your PHP/Laravel application with Cloudflare bindings.
https://github.com/renoki-co/l1
ai cloudflare cloudflare-workers d1 database kv laravel php queues vectorize workers
Last synced: about 3 hours ago
JSON representation
Extend your PHP/Laravel application with Cloudflare bindings.
- Host: GitHub
- URL: https://github.com/renoki-co/l1
- Owner: renoki-co
- License: apache-2.0
- Created: 2023-06-08T18:20:54.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-02T09:48:38.000Z (9 months ago)
- Last Synced: 2024-06-30T13:24:54.395Z (7 months ago)
- Topics: ai, cloudflare, cloudflare-workers, d1, database, kv, laravel, php, queues, vectorize, workers
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 106
- Watchers: 5
- Forks: 13
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# L1 - Cloudflare bindings for Laravel
![CI](https://github.com/renoki-co/l1/workflows/CI/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/renoki-co/l1/branch/master/graph/badge.svg)](https://codecov.io/gh/renoki-co/l1/branch/master)
[![StyleCI](https://github.styleci.io/repos/651202208/shield?branch=master)](https://github.styleci.io/repos/651202208)
[![Latest Stable Version](https://poser.pugx.org/renoki-co/l1/v/stable)](https://packagist.org/packages/renoki-co/l1)
[![Total Downloads](https://poser.pugx.org/renoki-co/l1/downloads)](https://packagist.org/packages/renoki-co/l1)
[![Monthly Downloads](https://poser.pugx.org/renoki-co/l1/d/monthly)](https://packagist.org/packages/renoki-co/l1)
[![License](https://poser.pugx.org/renoki-co/l1/license)](https://packagist.org/packages/renoki-co/l1)Extend your PHP/Laravel application with Cloudflare bindings.
This package offers support for:
- [x] [Cloudflare D1](https://developers.cloudflare.com/d1)
- [ ] [Cloudflare KV](https://developers.cloudflare.com/kv/)
- [ ] [Cloudflare Queues](https://developers.cloudflare.com/queues)## π Installation
You can install the package via Composer:
```bash
composer require renoki-co/l1
```## π Usage
### D1 with raw PDO
Though D1 is not connectable via SQL protocols, it can be used as a PDO driver via the package connector. This proxies the query and bindings to the D1's `/query` endpoint in the Cloudflare API.
```php
use RenokiCo\L1\D1\D1Pdo;
use RenokiCo\L1\D1\D1PdoStatement;
use RenokiCo\L1\CloudflareD1Connector;$pdo = new D1Pdo(
dsn: 'sqlite::memory:', // irrelevant
connector: new CloudflareD1Connector(
database: 'your_database_id',
token: 'your_api_token',
accountId: 'your_cf_account_id',
),
);
```### D1 with Laravel
In your `config/database.php` file, add a new connection:
```php
'connections' => [
'd1' => [
'driver' => 'd1',
'prefix' => '',
'database' => env('CLOUDFLARE_D1_DATABASE_ID', ''),
'api' => 'https://api.cloudflare.com/client/v4',
'auth' => [
'token' => env('CLOUDFLARE_TOKEN', ''),
'account_id' => env('CLOUDFLARE_ACCOUNT_ID', ''),
],
],
]
```Then in your `.env` file, set up your Cloudflare credentials:
```
CLOUDFLARE_TOKEN=
CLOUDFLARE_ACCOUNT_ID=
CLOUDFLARE_D1_DATABASE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```The `d1`Β driver will proxy the PDO queries to the Cloudflare D1 API to run queries.
## π Testing
Start the built-in Worker that simulates the Cloudflare API:
```bash
cd tests/worker
npm ci
npm run start
```In a separate terminal, run the tests:
``` bash
vendor/bin/phpunit
```## π€ Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## π Security
If you discover any security related issues, please email instead of using the issue tracker.
## π Credits
- [Alex Renoki](https://github.com/rennokki)
- [All Contributors](../../contributors)