From 23c1b3de3c09443eb1daf6dcf2df62ddb1fea171 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Tue, 31 Dec 2019 07:48:37 +0000 Subject: [PATCH] Adds PostgreSQL scope driver --- CHANGELOG.md | 1 + README.md | 8 +++++++- src/ScopeDriverFactory.php | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66326a5..793a59c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,3 +14,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * [1.0.0](#400---2019-12-02) - Initial release * [1.1.0](#400---2019-12-05) - Adds ability to force scope driver in config * [1.1.1](#400---2019-12-31) - Removes default scope driver +* [1.2.0](#400---2019-12-31) - Adds PostgreSQL scope driver diff --git a/README.md b/README.md index 9e6715a..0ef1930 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,13 @@ Any missing config options will be replaced with the defaults defined in `config Under the hood, GeoScope uses different drivers to ensure that the distance queries are optimised to the database connection being used. Scope drivers correspond to the database drivers used by Laravel. GeoScope will automatically detect the database driver being used by Laravel and choose the correct scope driver for it. Out of the box GeoScope includes a MySQL scope driver -which uses the built in `ST_Distance_Sphere()` function. +which uses `ST_Distance_Sphere()` function and a PostgreSQL scope driver which uses `earth_distance`. + +**NOTE: The PostgreSQL driver requires you to have the postgres `earthdistance` module installed which can be done by executing the following SQL** +```sql +create extension if not exists cube; +create extension if not exists earthdistance; +``` #### Creating Custom Scope Drivers GeoScope allows you to define and register custom scope drivers. To create a custom scope driver create a class that extends diff --git a/src/ScopeDriverFactory.php b/src/ScopeDriverFactory.php index 116cb00..4edbcae 100644 --- a/src/ScopeDriverFactory.php +++ b/src/ScopeDriverFactory.php @@ -5,6 +5,7 @@ use Netsells\GeoScope\Exceptions\ScopeDriverNotFoundException; use Netsells\GeoScope\Interfaces\ScopeDriverInterface; use Netsells\GeoScope\ScopeDrivers\MySQLScopeDriver; +use Netsells\GeoScope\ScopeDrivers\PostgreSQLScopeDriver; class ScopeDriverFactory { @@ -13,6 +14,7 @@ class ScopeDriverFactory */ protected $registeredStrategies = [ 'mysql' => MySQLScopeDriver::class, + 'pgsql' => PostgreSQLScopeDriver::class, ]; /**