prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
583 stars 61 forks source link

Getting started with postgres #326

Open jly36963 opened 2 years ago

jly36963 commented 2 years ago

Issue

I'm trying to use quaint with postgres, and I'm having trouble building/using quaint.

Context

rustup 1.24.3 (ce5817a94 2021-05-31) rustc 1.57.0-nightly (308dffd25 2021-09-22) cargo 1.57.0-nightly (9a28ac83c 2021-09-18)

Cargo.toml

[package]
name = "my-quaint-example"
version = "0.1.0"
edition = "2021"

[dependencies]
quaint = { version = "0.1.13", features = ["pooled"] }
tokio = { version = "1.12.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
async-trait = "0.1.51"

Import errors

I get errors when I try to import pooled or single, as outlined here. I've tried using a bunch of different combinations of the following features in Cargo.toml, but I can't get the imports to resolve:

use async_trait::async_trait;
use quaint::{pooled::Quaint, prelude::*};
// use quaint::{prelude::*, single::Quaint};
use serde::{Deserialize, Serialize};
unresolved imports `quaint::pooled`, `quaint::single`
could not find `pooled` in `quaint`

Build errors

When I try to use any of the postgres features (ie full-postgresql), I get build errors:

Compiling rust_decimal v1.16.0
error[E0432]: unresolved import `byteorder`
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.16.0/src/db.rs:466:9
    |
466 |     use byteorder::{BigEndian, ReadBytesExt};
    |         ^^^^^^^^^ use of undeclared crate or module `byteorder`

error[E0432]: unresolved import `bytes`
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.16.0/src/db.rs:467:9
    |
467 |     use bytes::{BufMut, BytesMut};
    |         ^^^^^ use of undeclared crate or module `bytes`

error[E0599]: no method named `read_u16` found for struct `std::io::Cursor` in the current scope
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.16.0/src/db.rs:526:34
    |
526 |             let num_groups = raw.read_u16::<BigEndian>()?;
    |                                  ^^^^^^^^ method not found in `std::io::Cursor<&[u8]>`
    |
   ::: /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/io/util/async_read_ext.rs:424:16
    |
424 |             fn read_u16(&mut self) -> ReadU16;
    |                -------- the method is available for `Pin<&mut std::io::Cursor<&[u8]>>` here
    |
    = help: items from traits can only be used if the trait is in scope
help: consider wrapping the receiver expression with the appropriate type
    |
526 |             let num_groups = Pin::new(&mut raw).read_u16::<BigEndian>()?;
    |                              +++++++++++++    +
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
464 |     use gimli::endianity::Endianity;
    |
464 |     use gimli::read::reader::Reader;
    |
464 |     use object::endian::Endian;
    |
464 |     use byteorder::io::ReadBytesExt;
    |
      and 1 other candidate

error[E0599]: no method named `read_i16` found for struct `std::io::Cursor` in the current scope
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.16.0/src/db.rs:527:30
    |
527 |             let weight = raw.read_i16::<BigEndian>()?; // 10000^weight
    |                              ^^^^^^^^ method not found in `std::io::Cursor<&[u8]>`
    |
   ::: /Users/jlymecargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/io/util/async_read_ext.rs:462:16
    |
462 |             fn read_i16(&mut self) -> ReadI16;
    |                -------- the method is available for `Pin<&mut std::io::Cursor<&[u8]>>` here
    |
    = help: items from traits can only be used if the trait is in scope
help: consider wrapping the receiver expression with the appropriate type
    |
527 |             let weight = Pin::new(&mut raw).read_i16::<BigEndian>()?; // 10000^weight
    |                          +++++++++++++    +
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
464 |     use gimli::endianity::Endianity;
    |
464 |     use gimli::read::reader::Reader;
    |
464 |     use object::endian::Endian;
    |
464 |     use byteorder::io::ReadBytesExt;
    |
      and 1 other candidate

error[E0599]: no method named `read_u16` found for struct `std::io::Cursor` in the current scope
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.16.0/src/db.rs:529:28
    |
529 |             let sign = raw.read_u16::<BigEndian>()?;
    |                            ^^^^^^^^ method not found in `std::io::Cursor<&[u8]>`
    |
   ::: /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/io/util/async_read_ext.rs:424:16
    |
424 |             fn read_u16(&mut self) -> ReadU16;
    |                -------- the method is available for `Pin<&mut std::io::Cursor<&[u8]>>` here
    |
    = help: items from traits can only be used if the trait is in scope
help: consider wrapping the receiver expression with the appropriate type
    |
529 |             let sign = Pin::new(&mut raw).read_u16::<BigEndian>()?;
    |                        +++++++++++++    +
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
464 |     use gimli::endianity::Endianity;
    |
464 |     use gimli::read::reader::Reader;
    |
464 |     use object::endian::Endian;
    |
464 |     use byteorder::io::ReadBytesExt;
    |
      and 1 other candidate

error[E0599]: no method named `read_u16` found for struct `std::io::Cursor` in the current scope
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.16.0/src/db.rs:531:29
    |
531 |             let scale = raw.read_u16::<BigEndian>()?;
    |                             ^^^^^^^^ method not found in `std::io::Cursor<&[u8]>`
    |
   ::: /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/io/util/async_read_ext.rs:424:16
    |
424 |             fn read_u16(&mut self) -> ReadU16;
    |                -------- the method is available for `Pin<&mut std::io::Cursor<&[u8]>>` here
    |
    = help: items from traits can only be used if the trait is in scope
help: consider wrapping the receiver expression with the appropriate type
    |
531 |             let scale = Pin::new(&mut raw).read_u16::<BigEndian>()?;
    |                         +++++++++++++    +
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
464 |     use gimli::endianity::Endianity;
    |
464 |     use gimli::read::reader::Reader;
    |
464 |     use object::endian::Endian;
    |
464 |     use byteorder::io::ReadBytesExt;
    |
      and 1 other candidate

error[E0599]: no method named `read_u16` found for struct `std::io::Cursor` in the current scope
   --> /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.16.0/src/db.rs:536:33
    |
536 |                 groups.push(raw.read_u16::<BigEndian>()?);
    |                                 ^^^^^^^^ method not found in `std::io::Cursor<&[u8]>`
    |
   ::: /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/io/util/async_read_ext.rs:424:16
    |
424 |             fn read_u16(&mut self) -> ReadU16;
    |                -------- the method is available for `Pin<&mut std::io::Cursor<&[u8]>>` here
    |
    = help: items from traits can only be used if the trait is in scope
help: consider wrapping the receiver expression with the appropriate type
    |
536 |                 groups.push(Pin::new(&mut raw).read_u16::<BigEndian>()?);
    |                             +++++++++++++    +
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
464 |     use gimli::endianity::Endianity;
    |
464 |     use gimli::read::reader::Reader;
    |
464 |     use object::endian::Endian;
    |
464 |     use byteorder::io::ReadBytesExt;
    |
      and 1 other candidate

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `rust_decimal` due to 7 previous errors

Examples

Are there code examples I can use to figure out what I'm missing in my Cargo.toml & code?

izznatsir commented 2 years ago

Try use github master branch version instead of the stable version. Then follow the master branch doc instruction, the link is available in README.

[dependencies]
quaint = { git = "https://github.com/prisma/quaint" }