pichibw
September 1, 2023, 7:08pm
1
Hi, i use debian 11 and i try use orm diesel, but this gave me error dependencies:
cargo install diesel_cli --no-default-features --features sqlite
ERROR:
= note: /usr/bin/ld: cannot find -lsqlite3
collect2: error: ld returned 1 exit status
how to solve ??
Gilnaa
September 1, 2023, 7:12pm
2
You need to install sqlite on your system:
sudo apt install sqlite3
See this section of the documentation, where they describe what you need to install, or how to disable the features that require sqlite3:
https://diesel.rs/guides/getting-started
(Specifically under the title " A note on installing diesel_cli
")
2 Likes
pichibw
September 1, 2023, 7:29pm
3
Gilnaa:
apt install sqlite3
Nothing happens, continue the error:
= note: /usr/bin/ld: cannot find -lsqlite3
collect2: error: ld returned 1 exit status
is neccesary restart my system ?
If it is still not working after installing sqlite3, you can use the bundled installation:
cargo install diesel_cli --no-default-features --features "sqlite-bundled"
From here: https://github.com/diesel-rs/diesel/tree/master/diesel_cli#installation
1 Like
mpol
September 1, 2023, 9:29pm
5
Actually the package you need to install is libsqlite3-dev
not sqlite3
.
2 Likes
pichibw
September 2, 2023, 1:57am
7
Hi, another problem, when i run command:
diesel migration run
error:
Unsupported type: serial
my file up.sql:
-- Your SQL goes here
CREATE TABLE books (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
year INTEGER,
country TEXT NOT NULL
);
whats wrong ??
SERIAL is not a valid data type in SQLite. Use INTEGER instead.
CREATE TABLE books (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
year INTEGER,
country TEXT NOT NULL
);
1 Like
pichibw
September 3, 2023, 7:22pm
9
Hi, this is my idea with me struct to connect and insert ???
suggest ??
struct Database {
connection: SqliteConnection,
}
impl Database {
pub fn new() -> Self {
dotenv().ok();
let database_url = env::var("DATABASE_URL")
.expect("DATABASE_URL in .env");
let connection = SqliteConnection::establish(&database_url)
.expect("error connecting DB");
Database {connection}
}
pub fn create_book(&self, title:&str, year:&str, country:&str) {
let new_book = (title, year, country);
use crate::books::dsl::books;
diesel::insert_into(books)
.values(&new_book)
.execute(&self.connection)
.expect("Error inserting book");
}
}
system
Closed
December 2, 2023, 7:23pm
10
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.