Skip to content

Commit

Permalink
Merge pull request #69 from efcor/master
Browse files Browse the repository at this point in the history
update for Laravel 11
  • Loading branch information
efcor authored Aug 6, 2024
2 parents 692ebe1 + fdeea98 commit 144e9e9
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 290 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2, 8.3]
php: [8.2, 8.3]
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

steps:
Expand All @@ -43,18 +43,14 @@ jobs:
tools: composer:v2, pecl
coverage: none

- name: Setup OCI8 for PHP 8.1
run: ./scripts/oci81.sh
if: matrix.php == 8.1

- name: Setup OCI8 for PHP 8.2
run: ./scripts/oci82.sh
if: matrix.php == 8.2

- name: Setup OCI8 for PHP 8.3
run: ./scripts/oci83.sh
if: matrix.php == 8.3

- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jfelder/oracledb",
"description": "Oracle DB driver for Laravel",
"keywords": ["oracle", "laravel", "laravel 10", "pdo_oci", "oci8"],
"keywords": ["oracle", "laravel", "laravel 11", "pdo_oci", "oci8"],
"license": "MIT",
"authors": [
{
Expand All @@ -10,13 +10,13 @@
}
],
"require": {
"php": "^8.1",
"illuminate/database": "^10.0",
"illuminate/pagination": "^10.0"
"php": "^8.2",
"illuminate/database": "^11.0",
"illuminate/pagination": "^11.0"
},
"require-dev": {
"mockery/mockery": "^1.5.1",
"phpunit/phpunit": "^10.0.7",
"mockery/mockery": "^1.6",
"phpunit/phpunit": "^11.0.1",
"laravel/pint": "^1.13"
},
"autoload": {
Expand Down
21 changes: 8 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
## Laravel Oracle Database Package

### OracleDB (updated for Laravel 10)
### OracleDB (updated for Laravel 11)

<a href="https://github.com/jfelder/Laravel-OracleDB/actions"><img src="https://github.com/jfelder/Laravel-OracleDB/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/jfelder/oracledb"><img src="https://img.shields.io/packagist/dt/jfelder/oracledb" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/jfelder/oracledb"><img src="https://img.shields.io/packagist/v/jfelder/oracledb" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/jfelder/oracledb"><img src="https://img.shields.io/packagist/l/jfelder/oracledb" alt="License"></a>


OracleDB is an Oracle Database Driver package for [Laravel Framework](https://laravel.com) - thanks [@taylorotwell](https://github.com/taylorotwell). OracleDB is an extension of [Illuminate/Database](https://github.com/illuminate/database) that uses the [OCI8 Functions](https://www.php.net/manual/en/ref.oci8.php) wrapped into the PDO namespace.

> **Note:** This package is designed to run in PHP 8.1, and has not been tested in PHP 8.0
**Please report any bugs you may find.**

- [Installation](#installation)
Expand Down Expand Up @@ -98,6 +95,7 @@ features not already listed.

#### Query Builder

- group limiting via a groupLimit clause `$query->groupLimit($value, $column);` note: this was only added to Laravel so Eloquent can limit the number of eagerly loaded results per parent
- insertOrIgnore `DB::from('users')->insertOrIgnore(['email' => 'foo']);`
- insertGetId with empty values `DB::from('users')->insertGetId([]);` (but calling with non-empty values is supported)
- upserts `DB::from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email');`
Expand All @@ -106,6 +104,11 @@ features not already listed.
- json operations `DB::from('users')->where('items->sku', '=', 'foo-bar')->get();`
- whereFulltext `DB::table('users')->whereFulltext('description', 'Hello World');`

#### Eloquent

- setting $guarded on an Eloquent model as anything other than an empty array. your models must either not define $guarded at all, or set it to an empty array. If not, Eloquent may attempt to run a column listing sql query resulting in an exception.
- limiting the number of eagerly loaded results per parent, ie get only 3 posts per user `User::with(['posts' => fn ($query) => $query->limit(3)])->paginate();`

#### Schema Builder

- drop a table if it exists `Schema::dropIfExists('some_table');`
Expand All @@ -129,15 +132,7 @@ features not already listed.
- create a column to hold IP addresses `$blueprint->ipAddress('foo')` (would be implemented as varchar2 45)
- create a column to hold MAC addresses `$blueprint->macAddress('foo')` (would be implemented as varchar2 17)
- create a geometry column `$blueprint->geometry('coordinates')`
- create a geometric point column `$blueprint->point('coordinates')`
- create a geometric point column specifying srid `$blueprint->point('coordinates', 4326)`
- create a linestring column `$blueprint->linestring('coordinates')`
- create a polygon column `$blueprint->polygon('coordinates')`
- create a geometry collection column `$blueprint->geometrycollection('coordinates')`
- create a multipoint column `$blueprint->multipoint('coordinates')`
- create a multilinestring column `$blueprint->multilinestring('coordinates')`
- create a multipolygon column `$blueprint->multipolygon('coordinates')`
- create a double column without specifying second or third parameters `$blueprint->double('foo')` (but `$blueprint->double('foo', 5, 2)` is supported)
- create a geography column `$blueprint->geography('coordinates')`
- create a timestamp column with `useCurrent` modifier `$blueprint->timestamp('created_at')->useCurrent()`

### License
Expand Down
28 changes: 0 additions & 28 deletions scripts/oci81.sh

This file was deleted.

39 changes: 28 additions & 11 deletions src/Jfelder/OracleDB/OracleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use Illuminate\Database\Connection;
use Jfelder\OracleDB\PDO\OracleDriver;
use Jfelder\OracleDB\Query\Grammars\OracleGrammar as QueryGrammar;
use Jfelder\OracleDB\Query\OracleBuilder as OracleQueryBuilder;
use Jfelder\OracleDB\Query\Processors\OracleProcessor;
Expand All @@ -14,6 +13,24 @@

class OracleConnection extends Connection
{
/**
* {@inheritdoc}
*/
public function getDriverTitle()
{
return 'Oracle';
}

/**
* Get the server version for the connection.
*
* @return string
*/
public function getServerVersion(): string
{
return 'Run SELECT * FROM V$VERSION; to get the Oracle server version.';
}

/**
* Get a schema builder instance for the connection.
*
Expand Down Expand Up @@ -74,16 +91,6 @@ protected function getDefaultPostProcessor()
return new OracleProcessor;
}

/**
* Get the Doctrine DBAL driver.
*
* @return \Doctrine\DBAL\Driver\OCI8\Driver
*/
protected function getDoctrineDriver()
{
return new OracleDriver;
}

/**
* Bind values to their parameters in the given statement.
*
Expand Down Expand Up @@ -144,4 +151,14 @@ protected function isUniqueConstraintError(Exception $exception)
{
return boolval(preg_match('#ORA-00001: unique constraint#i', $exception->getMessage()));
}

/**
* Get the schema state for the connection.
*
* @throws \RuntimeException
*/
public function getSchemaState(string $dummyArg1 = null, string $dummyArg2 = null)
{
throw new RuntimeException('Schema dumping is not supported when using Oracle.');
}
}
19 changes: 0 additions & 19 deletions src/Jfelder/OracleDB/PDO/OracleDriver.php

This file was deleted.

51 changes: 51 additions & 0 deletions src/Jfelder/OracleDB/Query/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public function compileSelect(Builder $query)
return $sql;
}

/**
* Compile a "where like" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereLike(Builder $query, $where)
{
if (! $where['caseSensitive']) {
throw new RuntimeException('This database engine does not support case insensitive like operations. The sql "UPPER(some_column) like ?" can accomplish insensitivity.');
}

$where['operator'] = $where['not'] ? 'not like' : 'like';

return $this->whereBasic($query, $where);
}

/**
* Compile an insert statement into SQL.
*
Expand Down Expand Up @@ -284,6 +302,29 @@ protected function compileLimit(Builder $query, $limit)
return '';
}

/**
* Compile a group limit clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
protected function compileGroupLimit(Builder $query)
{
throw new RuntimeException('This database engine does not support group limit operations.');
}

/**
* Compile a row number clause.
*
* @param string $partition
* @param string $orders
* @return string
*/
protected function compileRowNumber($partition, $orders)
{
throw new RuntimeException('This database engine does not support row number operations.');
}

/**
* Compile the "offset" portions of the query.
*
Expand All @@ -295,6 +336,16 @@ protected function compileOffset(Builder $query, $offset)
return '';
}

/**
* Compile a query to get the number of open connections for a database.
*
* @throws RuntimeException
*/
public function compileThreadCount()
{
throw new RuntimeException('This database engine does not support getting the number of open connections.');
}

/**
* Wrap a single string in keyword identifiers.
*
Expand Down
17 changes: 0 additions & 17 deletions src/Jfelder/OracleDB/Query/Processors/OracleProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,4 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu
{
return $query->getConnection()->oracleInsertGetId($sql, $values);
}

/**
* Process the results of a column listing query.
*
* @param array $results
* @return array
*/
public function processColumnListing($results)
{
$mapping = function ($r) {
$r = (object) $r;

return $r->column_name;
};

return array_map($mapping, $results);
}
}
24 changes: 14 additions & 10 deletions src/Jfelder/OracleDB/Schema/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,23 @@ public function compileCreate(Blueprint $blueprint, Fluent $command)
}

/**
* Compile a create table command.
* Compile a column addition table command.
*
* @param Illuminate\Database\Schema\Blueprint $blueprint
* @param Illuminate\Support\Fluent $command
* @return string
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
{
$columns = implode(', ', $this->getColumns($blueprint));
$column = $this->getColumn($blueprint, $command->column);

$sql = 'alter table '.$this->wrapTable($blueprint)." add ( $columns";
$sql = 'alter table '.$this->wrapTable($blueprint)." add ( $column";

$sql .= (string) $this->addPrimaryKeys($blueprint);
$primary = $this->getCommandByName($blueprint, 'primary');

if (! is_null($primary) && in_array($command->column->name, $primary->columns)) {
$sql .= ", constraint {$primary->index} primary key ( {$command->column->name} )";
}

return $sql .= ' )';
}
Expand Down Expand Up @@ -470,7 +474,11 @@ protected function typeTinyInteger(Fluent $column)
*/
protected function typeFloat(Fluent $column)
{
return "number({$column->total}, {$column->places})";
if ($column->precision) {
return "float({$column->precision})";
}

return 'float';
}

/**
Expand All @@ -480,11 +488,7 @@ protected function typeFloat(Fluent $column)
*/
protected function typeDouble(Fluent $column)
{
if (is_null($column->total) || is_null($column->places)) {
throw new RuntimeException('This database engine requires specifying both precision and scale for a "double" column.');
}

return "number({$column->total}, {$column->places})";
return 'double precision';
}

/**
Expand Down
Loading

0 comments on commit 144e9e9

Please sign in to comment.