Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Integration branch] feat: geospatial types support #4427

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/quaint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
features:
- "--lib --features=all"
- "--lib --no-default-features --features=sqlite"
- "--lib --no-default-features --features=sqlite --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=sqlite --features=gis --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql"
- "--lib --no-default-features --features=postgresql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql --features=gis --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql"
- "--lib --no-default-features --features=mysql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql --features=gis --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql"
- "--lib --no-default-features --features=mssql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql --features=gis --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--doc --features=all"
env:
TEST_MYSQL: "mysql://root:prisma@localhost:3306/prisma"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/query-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
single_threaded: true
connector: "postgres"
version: "15"
- name: "postgis15"
single_threaded: true
connector: "postgres"
version: "15-postgis"
- name: "mssql_2022"
single_threaded: false
connector: "sqlserver"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/schema-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
url: "postgresql://postgres:prisma@localhost:5437"
- name: postgres15
url: "postgresql://postgres:prisma@localhost:5438"
- name: postgis15
url: "postgresql://postgres:prisma@localhost:5439"
- name: cockroach_23_1
url: "postgresql://prisma@localhost:26260"
- name: cockroach_22_2
Expand Down
1 change: 1 addition & 0 deletions .test_database_urls/postgis_15
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export TEST_DATABASE_URL="postgresql://postgres:prisma@localhost:5439"
91 changes: 91 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ features = [
"postgresql",
"sqlite",
"uuid",
"gis",
]

[profile.dev.package.backtrace]
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ start-postgres15:
dev-postgres15: start-postgres15
cp $(CONFIG_PATH)/postgres15 $(CONFIG_FILE)

start-postgis15:
docker compose -f docker-compose.yml up -d --remove-orphans postgis15

dev-postgis15: start-postgis15
cp $(CONFIG_PATH)/postgis15 $(CONFIG_FILE)

start-cockroach_23_1:
docker compose -f docker-compose.yml up -d --remove-orphans cockroach_23_1

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prisma Engines
# Prisma Engines

[![Query Engine](https://github.com/prisma/prisma-engines/actions/workflows/query-engine.yml/badge.svg)](https://github.com/prisma/prisma-engines/actions/workflows/query-engine.yml)
[![Schema Engine + sql_schema_describer](https://github.com/prisma/prisma-engines/actions/workflows/schema-engine.yml/badge.svg)](https://github.com/prisma/prisma-engines/actions/workflows/schema-engine.yml)
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ services:
networks:
- databases

postgis15:
image: postgis/postgis:15-3.3
restart: always
command: postgres -c 'max_connections=1000'
environment:
POSTGRES_PASSWORD: "prisma"
POSTGRES_HOST_AUTH_METHOD: "md5"
POSTGRES_INITDB_ARGS: "--auth-host=md5"
ports:
- "5439:5432"
networks:
- databases

mysql-5-6:
image: mysql:5.6.50
command: mysqld
Expand Down
4 changes: 4 additions & 0 deletions libs/prisma-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum PrismaValue {
Uuid(Uuid),
List(PrismaListValue),
Json(String),
GeoJson(String),
Geometry(String),

/// A collections of key-value pairs constituting an object.
#[serde(serialize_with = "serialize_object")]
Expand Down Expand Up @@ -318,6 +320,8 @@ impl fmt::Display for PrismaValue {
PrismaValue::Null => "null".fmt(f),
PrismaValue::Uuid(x) => x.fmt(f),
PrismaValue::Json(x) => x.fmt(f),
PrismaValue::GeoJson(x) => x.fmt(f),
PrismaValue::Geometry(x) => x.fmt(f),
PrismaValue::BigInt(x) => x.fmt(f),
PrismaValue::List(x) => {
let as_string = format!("{x:?}");
Expand Down
9 changes: 7 additions & 2 deletions libs/test-setup/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ pub(crate) fn get_postgres_tags(database_url: &str) -> Result<BitFlags<Tags>, St
let fut = async {
let quaint = Quaint::new(database_url).await.map_err(|err| err.to_string())?;
let mut tags = Tags::Postgres.into();
let version = quaint.version().await.map_err(|err| err.to_string())?;

match version {
if let Ok(_postgis_version) = quaint.query_raw("SELECT PostGIS_version()", &[]).await {
tags |= Tags::PostGIS;
}

let postgres_version = quaint.version().await.map_err(|err| err.to_string())?;

match postgres_version {
None => Ok(tags),
Some(version) => {
eprintln!("version: {version:?}");
Expand Down
18 changes: 18 additions & 0 deletions libs/test-setup/src/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use enumflags2::BitFlags;
use once_cell::sync::Lazy;
use quaint::{prelude::Queryable, single::Quaint};

use crate::{runtime::run_with_thread_local_runtime as tok, Tags};

pub fn sqlite_test_url(db_name: &str) -> String {
std::env::var("SQLITE_TEST_URL").unwrap_or_else(|_| format!("file:{}", sqlite_test_file(db_name)))
Expand All @@ -25,3 +29,17 @@ fn sqlite_test_file(db_name: &str) -> String {

file_path.to_string_lossy().into_owned()
}

pub(crate) fn get_sqlite_tags() -> Result<BitFlags<Tags>, String> {
let fut = async {
let mut tags: BitFlags<Tags> = Tags::Sqlite.into();
// The SpatiaLite extension is loaded by quaint, assuming the SPATIALITE_PATH env variable is set
// If the extension can be loaded in a dummy database, it means it will also be available for the tests
let quaint = Quaint::new_in_memory().map_err(|err| err.to_string())?;
if let Ok(_has_spatialite) = quaint.query_raw("SELECT spatialite_version();", &[]).await {
tags |= Tags::Spatialite;
}
Ok(tags)
};
tok(fut)
}
2 changes: 2 additions & 0 deletions libs/test-setup/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ tags![
CockroachDb221 = 1 << 19,
CockroachDb222 = 1 << 20,
CockroachDb231 = 1 << 21,
PostGIS = 1 << 22,
Spatialite = 1 << 23,
];

pub fn tags_from_comma_separated_list(input: &str) -> BitFlags<Tags> {
Expand Down
4 changes: 2 additions & 2 deletions libs/test-setup/src/test_api_args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{logging, mssql, mysql, postgres, Capabilities, Tags};
use crate::{logging, mssql, mysql, postgres, sqlite, Capabilities, Tags};
use enumflags2::BitFlags;
use once_cell::sync::Lazy;
use quaint::single::Quaint;
Expand Down Expand Up @@ -36,7 +36,7 @@ static DB_UNDER_TEST: Lazy<Result<DbUnderTest, String>> = Lazy::new(|| {
match prefix {
"file" | "sqlite" => Ok(DbUnderTest {
database_url,
tags: Tags::Sqlite.into(),
tags: sqlite::get_sqlite_tags()?,
capabilities: Capabilities::CreateDatabase.into(),
provider: "sqlite",
shadow_database_url,
Expand Down
2 changes: 1 addition & 1 deletion prisma-fmt/tests/native_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test_native_types_list_on_crdb() {

let result = prisma_fmt::native_types(schema.to_owned());
let expected = expect![[
r#"[{"name":"Bit","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]},{"name":"Bool","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Boolean"]},{"name":"Bytes","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Bytes"]},{"name":"Char","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]},{"name":"Date","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["DateTime"]},{"name":"Decimal","_number_of_args":0,"_number_of_optional_args":2,"prisma_types":["Decimal"]},{"name":"Float4","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Float"]},{"name":"Float8","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Float"]},{"name":"Inet","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["String"]},{"name":"Int2","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Int"]},{"name":"Int4","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Int"]},{"name":"Int8","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["BigInt"]},{"name":"JsonB","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Json"]},{"name":"Oid","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Int"]},{"name":"CatalogSingleChar","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["String"]},{"name":"String","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]},{"name":"Time","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Timestamp","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Timestamptz","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Timetz","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Uuid","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["String"]},{"name":"VarBit","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]}]"#
r#"[{"name":"Bit","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]},{"name":"Bool","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Boolean"]},{"name":"Bytes","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Bytes"]},{"name":"Char","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]},{"name":"Date","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["DateTime"]},{"name":"Decimal","_number_of_args":0,"_number_of_optional_args":2,"prisma_types":["Decimal"]},{"name":"Float4","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Float"]},{"name":"Float8","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Float"]},{"name":"Inet","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["String"]},{"name":"Int2","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Int"]},{"name":"Int4","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Int"]},{"name":"Int8","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["BigInt"]},{"name":"JsonB","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Json"]},{"name":"Oid","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["Int"]},{"name":"CatalogSingleChar","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["String"]},{"name":"String","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]},{"name":"Time","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Timestamp","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Timestamptz","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Timetz","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["DateTime"]},{"name":"Uuid","_number_of_args":0,"_number_of_optional_args":0,"prisma_types":["String"]},{"name":"VarBit","_number_of_args":0,"_number_of_optional_args":1,"prisma_types":["String"]},{"name":"Geometry","_number_of_args":0,"_number_of_optional_args":2,"prisma_types":["Geometry","GeoJson"]},{"name":"Geography","_number_of_args":0,"_number_of_optional_args":2,"prisma_types":["Geometry","GeoJson"]}]"#
]];
expected.assert_eq(&result);
}
Loading
Loading