Giter VIP home page Giter VIP logo

diesel-point's Introduction

diesel-point โ€ƒ Latest Version docs

Diesel support for Point types in Postgres

Example usage

In your sql schema, you have a column some_point_field Point not null. When Diesel generates the schema (using table! {}) this column will look like some_point_field -> Point. To ensure that the Point type is in scope, read this guide and add use diesel_point::sql_types::* to the import_types key in your diesel.toml file.

E.g. it will look like this:

[print_schema]
file = "src/schema.rs"

import_types = ["diesel::sql_types::*", "diesel_point::sql_types::*"]

In your ORM struct, write some_point_field: PointXy.

Now you can use this struct / table in your diesel queries.

If your table has already been created, first run diesel migration revert. Use PointXy in the ORM struct, and then run the migration again.

Example

#[derive(Insertable, Queryable, Identifiable, Serialize, PartialEq, Debug, Clone, AsChangeset)]
#[diesel(primary_key(model_id))]
#[diesel(table_name = my_table)]
pub struct Mytable{
    pub model_id: Uuid,
    pub some_point_field: PointXy,
}

diesel-point's People

Contributors

fernandomarca avatar

Stargazers

Giovanni Berti avatar

Watchers

 avatar

diesel-point's Issues

Add `generate_missing_sql_type_definitions = false` to README

Hi, I used your library and found necessary to also add generate_missing_sql_type_definitions = false to diesel.toml, otherwise I got the following error, even after redoing diesel migrations

error[E0277]: the trait bound `PointXy: FromSqlRow<schema::sql_types::Point, Pg>` is not satisfied
  --> src/models.rs:35:19
   |
35 |     pub position: PointXy,
   |                   ^^^^^^^ the trait `FromSql<schema::sql_types::Point, Pg>` is not implemented for `PointXy`, which is required by `PointXy: FromSqlRow<schema::sql_types::Point, Pg>`
   |
   = help: the trait `FromSql<diesel_point::sql_types::Point, Pg>` is implemented for `PointXy`
   = help: for that trait implementation, expected `diesel_point::sql_types::Point`, found `schema::sql_types::Point`
   = note: required for `PointXy` to implement `diesel::Queryable<schema::sql_types::Point, Pg>`
   = note: required for `PointXy` to implement `FromSqlRow<schema::sql_types::Point, Pg>`
   = help: see issue #48214

For more information about this error, try `rustc --explain E0277`.
error: could not compile `my-project` (bin "my-project") due to 1 previous error

Thanks again for the library :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.