Giter Club home page Giter Club logo

Comments (4)

TheConner avatar TheConner commented on June 6, 2024 1

A potential workaround is to tell Diesel not to generate missing SQL type definitions and then manually specify them yourself. For my MWE the [print_schema] section of diesel.toml will become

[print_schema]
file = "src/schema.rs"
generate_missing_sql_type_definitions = false
import_types = ["diesel::sql_types::*", "diesel_ltree::sql_types::Ltree"]

And then the schema generated by diesel will work fine.

Edit: If you need the functionality provided by Diesel automatically generating missing types, an alternative is to use the patch file functionality described in the Diesel CLI docs. Using the patch file, I can target specific lines in schema.rs to replace the auto-generated ltree type with the one provided by this library.

from diesel_ltree.

kivikakk avatar kivikakk commented on June 6, 2024

Can you let me know how I can reproduce this same compile error locally? What do your project's Cargo.toml and Cargo.lock look like? (or at least all the lines related to Diesel/diesel_ltree.) What line of which file is actually shown there?

I've spent half an hour trying to reproduce what I thought the problem would be, given what you've described, but no luck. Let me know!

from diesel_ltree.

TheConner avatar TheConner commented on June 6, 2024

I ran into this problem, given the lack of MWE I think I can help out by contributing one. The problem here seems to be with how diesel_ltree interacts with the code generated by Diesel. In my MWE, this table

CREATE TABLE foo (
  id SERIAL PRIMARY KEY,
  tree_path LTREE NOT NULL
);

Ends up creating the following schema.rs:

// @generated automatically by Diesel CLI.

pub mod sql_types {
    #[derive(diesel::sql_types::SqlType)]
    #[diesel(postgres_type(name = "ltree"))]
    pub struct Ltree;
}

diesel::table! {
    use diesel::sql_types::*;
    use super::sql_types::Ltree;

    foo (id) {
        id -> Int4,
        tree_path -> Ltree,
    }
}

And in its current state, if you attempt to do anything with the foo table (select, insert etc) you will end up with the errors reported by the poster. If you replace use super::sql_types::Ltree; with diesel_ltree::sql_types::Ltree;, all of the traits implemented by diesel_ltree are picked up and everything works fine.

from diesel_ltree.

kivikakk avatar kivikakk commented on June 6, 2024

Oof, I see. It looks like this is the best we can do with print_schema, so I'd say import_types + patch_file is indeed the path forward for such uses.

In #25 I'm updating the built-in tests to use this instead of issuing table! manually.

@TheConner — thank you so much for putting that example together! I appreciate it a heap. ❤️

from diesel_ltree.

Related Issues (12)

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.