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

Update for diesel 2.0 #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diesel_geometry"
version = "1.4.0"
version = "2.0.0"
authors = ["YetAnotherMinion <[email protected]>"]
license = "MIT OR Apache-2.0"
description = "Adds support for geometric types and functions to Diesel."
Expand All @@ -12,7 +12,7 @@ categories = ["database"]

[dependencies]
byteorder = "1.0"
diesel = { version = ">=1.2, <1.5", features = ["postgres"] }
diesel = { version = "2", features = ["postgres"] }
serde = { version = "1.0", features = ["derive"], optional = true }

[dev-dependencies]
Expand Down
18 changes: 9 additions & 9 deletions src/doctest_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extern crate cfg_if;
extern crate dotenv;

use diesel::prelude::*;
use diesel::{prelude::*, connection::SimpleConnection};
use diesel_geometry::prelude::*;
use self::dotenv::dotenv;

Expand All @@ -17,30 +17,30 @@ cfg_if! {
}

fn connection_no_data() -> PgConnection {
let connection = connection_no_transaction();
let mut connection = connection_no_transaction();
connection.begin_test_transaction().unwrap();
connection.execute("DROP TABLE IF EXISTS drawings CASCADE").unwrap();
connection.execute("DROP TABLE IF EXISTS shapes CASCADE").unwrap();
connection.batch_execute("DROP TABLE IF EXISTS drawings CASCADE").unwrap();
connection.batch_execute("DROP TABLE IF EXISTS shapes CASCADE").unwrap();

connection
}

#[allow(dead_code)]
fn establish_connection() -> PgConnection {
let connection = connection_no_data();
let mut connection = connection_no_data();

connection.execute("CREATE TABLE drawings (
connection.batch_execute("CREATE TABLE drawings (
id SERIAL PRIMARY KEY,
title VARCHAR NOT NULL
)").unwrap();
connection.execute("INSERT INTO drawings (title) VALUES ('Cubism'), ('Airplanes')").unwrap();
connection.batch_execute("INSERT INTO drawings (title) VALUES ('Cubism'), ('Airplanes')").unwrap();

connection.execute("CREATE TABLE shapes (
connection.batch_execute("CREATE TABLE shapes (
id SERIAL PRIMARY KEY,
drawing_id INTEGER NOT NULL,
centroid POINT
)").unwrap();
connection.execute("INSERT INTO shapes (drawing_id, centroid) VALUES
connection.batch_execute("INSERT INTO shapes (drawing_id, centroid) VALUES
(1, point '(0, 0)'),
(2, point '(1,2)')").unwrap();

Expand Down
20 changes: 10 additions & 10 deletions src/pg/expression/expression_methods.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use diesel::expression::{AsExpression, Expression};
use diesel::pg::expression::operators::IsContainedBy;

use super::operators::SameAs;
use super::operators::{IsContainedBy, SameAs};
use sql_types::{self, Circle, Point};

pub trait PgSameAsExpressionMethods<ST>: Expression + Sized {
pub trait PgSameAsExpressionMethods<ST: diesel::sql_types::SingleValue>: Expression + Sized {
/// Creates a PostgresSQL `~=` expression.
///
/// The "same as" operator, ~=, represents the usual notion of equality for the `point`, `box`,
Expand All @@ -22,14 +21,14 @@ pub trait PgSameAsExpressionMethods<ST>: Expression + Sized {
/// #
/// # fn main() {
/// # use schema::shapes::dsl::*;
/// # let connection = establish_connection();
/// # let mut connection = establish_connection();
/// let found_drawing_id = shapes
/// .select(drawing_id)
/// .filter(centroid.same_as(PgPoint(1.0, 2.0)))
/// .first(&connection);
/// .first(&mut connection);
/// assert_eq!(Ok(2), found_drawing_id);
/// # }
fn same_as<T>(self: Self, other: T) -> SameAs<Self, T::Expression>
fn same_as<T>(self, other: T) -> SameAs<Self, T::Expression>
where
T: AsExpression<ST>,
{
Expand All @@ -41,7 +40,7 @@ impl<T: Expression<SqlType = Point>> PgSameAsExpressionMethods<Point> for T {}
impl<T: Expression<SqlType = sql_types::Box>> PgSameAsExpressionMethods<sql_types::Box> for T {}
impl<T: Expression<SqlType = Circle>> PgSameAsExpressionMethods<Circle> for T {}

pub trait PgIsContainedByExpressionMethods<ST>: Expression + Sized {
pub trait PgIsContainedByExpressionMethods<ST: diesel::sql_types::SingleValue>: Expression + Sized {
/// Creates a PostgresSQL `<@` expression.
///
/// For geometric types.
Expand All @@ -57,7 +56,7 @@ pub trait PgIsContainedByExpressionMethods<ST>: Expression + Sized {
/// #
/// # fn main() {
/// # use schema::shapes::dsl::*;
/// # let connection = establish_connection();
/// # let mut connection = establish_connection();
/// // Looking for point at (1,2)
/// let found_drawing_id = shapes
/// .select(drawing_id)
Expand All @@ -66,10 +65,11 @@ pub trait PgIsContainedByExpressionMethods<ST>: Expression + Sized {
/// PgBox(PgPoint(0.5, 1.5), PgPoint(3.0,5.0)).into_sql::<sql_types::Box>()
/// )
/// )
/// .first(&connection);
/// .first(&mut connection);
/// assert_eq!(Ok(2), found_drawing_id);
/// # }
fn is_contained_by<T>(self: Self, other: T) -> IsContainedBy<Self, T::Expression>
#[allow(clippy::wrong_self_convention)]
fn is_contained_by<T>(self, other: T) -> IsContainedBy<Self, T::Expression>
where
T: AsExpression<ST>,
{
Expand Down
3 changes: 2 additions & 1 deletion src/pg/expression/operators.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use diesel::pg::Pg;

diesel_infix_operator!(SameAs, " ~= ", backend: Pg);
infix_operator!(SameAs, " ~= ", backend: Pg);
infix_operator!(IsContainedBy, " <@ ", backend: Pg);
Loading