Skip to content

Commit

Permalink
Automatically replace the libsql:// protocol in the database URL to b…
Browse files Browse the repository at this point in the history
…e https:// protocol
  • Loading branch information
richan-fongdasen committed Nov 7, 2024
1 parent a5c1623 commit 0ce0a8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Database/TursoConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
use Illuminate\Database\Connection;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use PDO;
use RichanFongdasen\Turso\Jobs\TursoSyncJob;

class TursoConnection extends Connection
{
public function __construct(TursoPDO $pdo, string $database = ':memory:', string $tablePrefix = '', array $config = [])
{
if (isset($config['db_url']) && Str::startsWith($config['db_url'], 'libsql:')) {
$config['db_url'] = Str::replaceFirst('libsql:', 'https:', $config['db_url']);
}

parent::__construct($pdo, $database, $tablePrefix, $config);

$this->schemaGrammar = $this->getDefaultSchemaGrammar();
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/Database/TursoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@
expect($log)->toBeArray()
->and($log)->toHaveCount(0);
})->group('TursoConnectionTest', 'UnitTest');

test('it will replace the libsql protocol in database url to be https protocol', function () {
config([
'database.connections.turso.db_url' => 'libsql://project-name.turso.io',
]);

expect(DB::connection('turso')->getConfig('db_url'))->toBe('https://project-name.turso.io');
})->group('TursoConnectionTest', 'UnitTest');

0 comments on commit 0ce0a8b

Please sign in to comment.