Skip to content

Commit

Permalink
sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Dec 28, 2023
1 parent 80d492b commit 52fa270
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 125 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"php": "^8.1",
"illuminate/database": "^10.0",
"illuminate/database": "^10.38",
"staudenmeir/eloquent-has-many-deep-contracts": "^1.1"
},
"require-dev": {
Expand Down
79 changes: 79 additions & 0 deletions src/Grammars/SqliteGrammar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Staudenmeir\EloquentJsonRelations\Grammars;

use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Query\Grammars\SQLiteGrammar as Base;
use RuntimeException;

class SqliteGrammar extends Base implements JsonGrammar
{
/**
* Compile a "JSON array" statement into SQL.
*
* @param string $column
* @return string
*/
public function compileJsonArray($column)
{
return $this->wrap($column);
}

/**
* Compile a "JSON object" statement into SQL.
*
* @param string $column
* @param int $levels
* @return string
*/
public function compileJsonObject($column, $levels)
{
throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore
}

/**
* Compile a "JSON value select" statement into SQL.
*
* @param string $column
* @return string
*/
public function compileJsonValueSelect(string $column): string
{
return $this->wrap($column);
}

/**
* Determine whether the database supports the "member of" operator.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @return bool
*/
public function supportsMemberOf(ConnectionInterface $connection): bool
{
return false;
}

/**
* Compile a "member of" statement into SQL.
*
* @param string $column
* @param string|null $objectKey
* @param mixed $value
* @return string
*/
public function compileMemberOf(string $column, ?string $objectKey, mixed $value): string
{
throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore
}

/**
* Prepare the bindings for a "member of" statement.
*
* @param mixed $value
* @return array
*/
public function prepareBindingsForMemberOf(mixed $value): array
{
throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore
}
}
3 changes: 3 additions & 0 deletions src/Relations/Traits/IsJsonRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Staudenmeir\EloquentJsonRelations\Grammars\JsonGrammar;
use Staudenmeir\EloquentJsonRelations\Grammars\MySqlGrammar;
use Staudenmeir\EloquentJsonRelations\Grammars\PostgresGrammar;
use Staudenmeir\EloquentJsonRelations\Grammars\SqliteGrammar;
use Staudenmeir\EloquentJsonRelations\Grammars\SqlServerGrammar;

trait IsJsonRelation
Expand Down Expand Up @@ -166,6 +167,8 @@ protected function getJsonGrammar(Builder $query): JsonGrammar
return $query->getConnection()->withTablePrefix(new MySqlGrammar());
case 'pgsql':
return $query->getConnection()->withTablePrefix(new PostgresGrammar());
case 'sqlite':
return $query->getConnection()->withTablePrefix(new SqliteGrammar());
case 'sqlsrv':
return $query->getConnection()->withTablePrefix(new SqlServerGrammar());
}
Expand Down
13 changes: 2 additions & 11 deletions tests/BelongsToJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@

class BelongsToJsonTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

if (DB::connection()->getDriverName() === 'sqlite') {
$this->markTestSkipped();
}
}

#[DataProvider(methodName: 'idRelationProvider')]
public function testLazyLoading(string $relation)
{
Expand Down Expand Up @@ -125,7 +116,7 @@ public function testExistenceQuery(string $relation)
#[DataProvider(methodName: 'objectRelationProvider')]
public function testExistenceQueryWithObjects(string $relation)
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -145,7 +136,7 @@ public function testExistenceQueryForSelfRelation()

public function testExistenceQueryForSelfRelationWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand Down
12 changes: 1 addition & 11 deletions tests/Concatenation/BelongsToJson/FirstPositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@

namespace Tests\Concatenation\BelongsToJson;

use Illuminate\Database\Capsule\Manager as DB;
use Tests\Models\User;
use Tests\TestCase;

class FirstPositionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

if (DB::connection()->getDriverName() === 'sqlite') {
$this->markTestSkipped();
}
}

public function testLazyLoading()
{
$permissions = User::find(21)->permissions;
Expand Down Expand Up @@ -85,7 +75,7 @@ public function testExistenceQuery()

public function testExistenceQueryWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand Down
16 changes: 3 additions & 13 deletions tests/Concatenation/BelongsToJson/IntermediatePositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@

namespace Tests\Concatenation\BelongsToJson;

use Illuminate\Database\Capsule\Manager as DB;
use Tests\Models\Country;
use Tests\TestCase;

class IntermediatePositionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

if (DB::connection()->getDriverName() === 'sqlite') {
$this->markTestSkipped();
}
}

public function testLazyLoading()
{
$permissions = Country::find(71)->permissions;
Expand All @@ -26,7 +16,7 @@ public function testLazyLoading()

public function testLazyLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -46,7 +36,7 @@ public function testEagerLoading()

public function testEagerLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -66,7 +56,7 @@ public function testExistenceQuery()

public function testExistenceQueryWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand Down
16 changes: 3 additions & 13 deletions tests/Concatenation/BelongsToJson/LastPositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@

namespace Tests\Concatenation\BelongsToJson;

use Illuminate\Database\Capsule\Manager as DB;
use Tests\Models\Country;
use Tests\TestCase;

class LastPositionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

if (DB::connection()->getDriverName() === 'sqlite') {
$this->markTestSkipped();
}
}

public function testLazyLoading()
{
$roles = Country::find(71)->roles;
Expand All @@ -26,7 +16,7 @@ public function testLazyLoading()

public function testLazyLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -46,7 +36,7 @@ public function testEagerLoading()

public function testEagerLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -66,7 +56,7 @@ public function testExistenceQuery()

public function testExistenceQueryWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand Down
18 changes: 4 additions & 14 deletions tests/Concatenation/HasManyJson/FirstPositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@

namespace Tests\Concatenation\HasManyJson;

use Illuminate\Database\Capsule\Manager as DB;
use Tests\Models\Role;
use Tests\TestCase;

class FirstPositionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

if (DB::connection()->getDriverName() === 'sqlite') {
$this->markTestSkipped();
}
}

public function testLazyLoading()
{
$countries = Role::find(2)->countries;
Expand All @@ -26,7 +16,7 @@ public function testLazyLoading()

public function testLazyLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -46,7 +36,7 @@ public function testEagerLoading()

public function testEagerLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand Down Expand Up @@ -77,7 +67,7 @@ public function testLazyEagerLoading()

public function testLazyEagerLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -97,7 +87,7 @@ public function testExistenceQuery()

public function testExistenceQueryWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand Down
16 changes: 3 additions & 13 deletions tests/Concatenation/HasManyJson/IntermediatePositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@

namespace Tests\Concatenation\HasManyJson;

use Illuminate\Database\Capsule\Manager as DB;
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
use Tests\Models\Permission;
use Tests\TestCase;

class IntermediatePositionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

if (DB::connection()->getDriverName() === 'sqlite') {
$this->markTestSkipped();
}
}

public function testLazyLoading()
{
$countries = Permission::find(83)->countries;
Expand All @@ -27,7 +17,7 @@ public function testLazyLoading()

public function testLazyLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -49,7 +39,7 @@ public function testEagerLoading()

public function testEagerLoadingWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand All @@ -69,7 +59,7 @@ public function testExistenceQuery()

public function testExistenceQueryWithObjects()
{
if (DB::connection()->getDriverName() === 'sqlsrv') {
if (in_array($this->database, ['sqlite', 'sqlsrv'])) {
$this->markTestSkipped();
}

Expand Down
Loading

0 comments on commit 52fa270

Please sign in to comment.