This site is built using pandoc. The content is available here: https://diesel.rs
Build locally
make page
Master branch is automatically deployed to Github Pages.
License: MIT License
This site is built using pandoc. The content is available here: https://diesel.rs
Build locally
make page
Master branch is automatically deployed to Github Pages.
Hi there,
I really like the guides you already have. I'd really like to see a guide on how to correctly run tests (ie #[cfg(test)] mod tests) or integrations tests with diesel to correctly do migrations, fixtures, and teardown. I don't see any resources about this today, but I think it would really help consumers of the library so there is "best way" to achieve this.
Thanks,
Hi, i just noticed that if I dont explicitly go to the https site I will stay on the http site that could be a security risk for some users.
Cheers Konrad
When running $ cargo install diesel_cli
on a Debian 9 machine I was getting:
= note: /usr/bin/ld: cannot find -lsqlite3
/usr/bin/ld: cannot find -lpq
/usr/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status
It might be useful if the guide mentioned what command to run to solve these issues, instead of "You can resolve this issue by either installing the library (using the usual way to do this depending on your operating system)".
In my case the issue was resolved by installing the following:
sudo apt install libpq-dev libmysqlclient-dev libsqlite3-dev
The footer is somewhat 'outdated', it reads at the moment: Copyright © 2015-2022 The Diesel Core Team
.
I will file a PR with an update to change 2022 to 2023. Edit: filed as #185
In Relations topic, "many-to-many or m:n" section, the "down" migration file for books_authors
table (DROP TABLE books_authors;
) should be renamed as down.sql
instead of up.sql
.
Diesel is stored in yellow containers so you can tell them apart from other fuels (red for gas, blue for kerosene, etc.).
In many areas of the world, it is illegal for a fuel station attendant to (re)fill fuel into the wrong-colored container for safety (and interoperability) reasons.
Just add something like
By the way, if you ever wonder what Rust code gets generated by these macros: If your
schema
is public, you can always runcargo doc --open
to render the documentation of your project and see what items it contains.
As preparation of the upcoming diesel 2.0 release we need to update the guides on our web page to reflect the corresponding changes.
For the ["Schema in depth"](https://diesel.rs/guides/schema-in-depth.html guide this involves the following points:
Please use this issue as discussion platform to ask any question that is unclear about updating this guide.
Just noticed this at the end of http://diesel.rs/guides/all-about-inserts/:
The Getting Started Guid is a great resource when getting started with Diesel. It goes though all of the basics quickly and clearly. Unfortunately, it's only written for PostgreSQL.
I'm not a professional programmer, I'm more of a weekend hobbyist. So this is more from a novices' stand point rather than a professional's. I think the best kinds of getting started guide or an introduction guide should use the simplest of technologies to get the a new user up and running with the least amount of friction. Using PostgreSQL doesn't fulfill that requirement. The user has to install PostgreSQL database, configure it, and run the server before even beginning the guide. The guide should focus on the simplest of technologies by default at least, which in this case, would be SQLite.
Although this might not seem like a big deal at first glance -- superficially it might seem simple enough for the reader to replace postgress
with the database technology they would like to use -- there's quite a number of issues that pops up where the solution is not obvious.
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
title VARCHAR NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL DEFAULT 'f'
)
SQLite doesn't support some of the types used in PostgreSQL:
This might be obvious to someone who works with SQLite but can be a source of frustration for someone planning to use SQLite for the first time.
Here's an example of a YouTuber explaining how to go about making changes to this example so it would work for SQLite.
#[macro_use]
extern crate diesel;
extern crate dotenv;
use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::env;
pub fn establish_connection() -> PgConnection {
dotenv().ok();
let database_url = env::var("DATABASE_URL")
.expect("DATABASE_URL must be set");
PgConnection::establish(&database_url)
.expect(&format!("Error connecting to {}", database_url))
}
Here the connector is made with diesel::pg::PgConnection;
. An astute reader will most likely realize that the use diesel::pg
contains methods for connecting to a PostgreSQL database. The reader would have to resort to reading the documentation to fix this line. Not the end of the world, and some might say that reading the manual is a good thing, but this is a Getting Started guide which should be a tutorial with the least amount of friction possible.
Here's an example of a YouTuber explaining how to go about making changes to this example so it would work for SQLite.
#[derive(Queryable)]
pub struct Post {
pub id: i32,
pub title: String,
pub body: String,
pub published: bool,
}
Same as the up.sql
example, SQLite does not support bool
types.
use self::models::{Post, NewPost};
pub fn create_post<'a>(conn: &PgConnection, title: &'a str, body: &'a str) -> Post {
use schema::posts;
let new_post = NewPost {
title: title,
body: body,
};
diesel::insert_into(posts::table)
.values(&new_post)
.get_result(conn)
.expect("Error saving new post")
}
The pub fn create_post<'a>(conn: &PgConnection, title: &'a str, body: &'a str) -> Post {
has to changed. Another problem is .get_result(conn)
which is not implemented for SQLite. This is not obvious. Achieving the same reuslt as this line is also not obvious.
A YouTuber explaining the problem.
These are only some of the firction when using the Getting Started Guid for a database technology other than PostgreSQL.
The solution is to have the same tutorial but with the snippets translated for each database supported by Diesel. This would also mean that the body of the guide has to be worded in a way that applies to all databases and when the details diverge, add a note box for the specific database.
Here's a mock-up of how the snippets can be toggled for each database.
Here's a mock-up of how special notes for the databases can be implemented.
Another way to achieve the same thing without coding a dynamic page would be to write a separate Getting Stated Guide with <name_of_database> guide for each database.
Thank you all for a fantastic library!
In the line
'And now, finally, we can see our post with `cargo run --bin show_posts`.'
the cargo command is not parsed as being bold (as the other cargo commands are.)
docker alpine rust
/app/diesel_demo # cargo -V
cargo 1.54.0 (5ae8d74b3 2021-06-22)
/app/diesel_demo # rustc -V
rustc 1.54.0 (a178d0322 2021-07-26)
/app/diesel_demo # diesel setup
Segmentation fault
/app/diesel_demo # diesel migration generate create_posts
Creating migrations/2021-08-07-020132_create_posts/up.sql
Creating migrations/2021-08-07-020132_create_posts/down.sql
/app/diesel_demo # diesel migration run
Segmentation fault
As preparation of the upcoming diesel 2.0 release we need to update the guides on our web page to reflect the corresponding changes.
For the "All about updates" guide this involves the following points:
Please use this issue as discussion platform to ask any question that is unclear about updating this guide.
Feedback from /u/cars10k on Reddit
Is there any repo to download precompiled binaries from or even better a GH action that saves the compilation step?
The white text on the light blue background is quite hard to read, especially since the text is so free floating on the page.
I've played around a bit and I'd suggest giving the content area a bit of a padding and a backgroudn color.
something like:
.guide-wrapper {
margin-right: 0;
padding: 20px 30px;
background: #3e4d66;
border-radius: 10px;
}
This would also require makign .guide-wrapper a bit larger in the @media css.
@media screen and (min-width: 53.75em) {
.guide-wrapper {
width: 70%
}
}
...
@corwinharrell
As preparation of the upcoming diesel 2.0 release we need to update the guides on our web page to reflect the corresponding changes.
For the "All about inserts" guide this involves the following points:
RETURNING
so that it mentions that support for RETURNING
clauses using the sqlite backend is behind a feature flag (returning_clauses_for_sqlite_3_35
)UPSERT
so that it applies to the SQLite backend as well.Please use this issue as discussion platform to ask any question that is unclear about updating this guide.
It seems that many people are afraid of automatic schema inference. While we shouldn't change the guide to not use infer_schema!
, we should probably mention in an info block that people can also use the table!
macro and diesel print-schema
on the CLI.
The main issue is the line:
let user_form = serde_json::from_str::>(json)?;
which should actually be:
let user_form = serde_json::from_str::<Vec<UserForm>>(json)?;
As per this. Not sure if this falls under the umbrella of #47 but wanted to note it here. I'm not too familiar with slim and I don't see anything obviously wrong with https://github.com/sgrif/diesel.rs-website/blob/master/source/views/guides/all-about-inserts.html.slim#L417 but perhaps I'm missing something obvious.
Looking at the rendered html it looks like <Vec<UserForm>
portion of the type is being rendered as html:
As the title says, this is not a bug or anything, just as suggestion that stop serving the site via http
& only use https
for the users to be able to access it.
Thanks.
I just saw a link for the Diesel website on lobste.rs, followed the link to the website, yet there is absolutely no information on the frontpage about what Diesel is, neither an about page, so I am left guessing looking at features.
I highly recommend that the first thing a persons sees, when visiting your website, is a clear cut message describing what Diesel is.
Just as an inspiration, take a look at https://www.postgresql.org/ or https://www.sqlite.org/ or https://www.openbsd.org/.
How up to date is the documentation in this page http://diesel.rs/guides/getting-started.html?
I can't seem to make it work. Once I try to compile I get these:
The first one "cannot find derive macro 'Queryable' in this scope is quite confusing because it comes from the file that was generated by diesel setup.
Postgres at least appears to have a limit of 65,535 rows per query, and diesel doesn't split the rows automatically, so it's up to the caller to do that.
when I run cargo install diesel_cli
toolchain = stable-x86_64-pc-windows-gnu
gcc-v = gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
note that when compile diesel_cli
note: D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsqlite3 D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpq D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmysql collect2.exe: error: ld returned 1 exit status
I authored stack-queue specifically so that I could create a data loader that integrates with Diesel. The current design only batches contiguous slices and simply starts a new batch whenever a task batch would otherwise wrap around to the beginning, however I could make this support wrap-around batching by returning an ordered pair of slices instead. The only way I could make this work and still integrate with BelongingToDsl without creating an intermediary Vec would be for BelongingToDsl to impl<'a, Parent, Child> BelongingToDsl<(&'a [Parent], &'a [Parent])> for Child
As preparation of the upcoming diesel 2.0 release we need to update the guides on our web page to reflect the corresponding changes.
For the "Composing Applications with Diesel" guide this involves the following points:
Please use this issue as discussion platform to ask any question that is unclear about updating this guide.
On screens such as Composing Applications with Diesel, the HTML class, guide-wrapper
, should not have its width
and margin-left
CSS properties set to any values. The region should be allowed to fill it container as that already provides sufficient padding. Currently, guide-wrapper
wast 2/3 of the width, annoyingly clipping the source code examples.
First, thanks for creating this excellent tutorial.
As I only have a single screen, I put the IDE on the left and this web page on the right.
As you narrow the browser window, to give more space in the IDE, the text column becomes narrower while wasting large margins at the sides.
It would be good if the wide margins were the first thing to go when making the page less than 1000px wide. (These margins are completely empty apart from the Diesel logo and two links at the top of the page, which could move inward at < 1000px as there is nothing in the centre.)
The version of pandoc being used by the CI to build the site, has a quite annoying accessibility issue surrounding code-blocks.
Every line in a codeblock has an <a>
tags with aria-hidden="true"
on it, linking to an id element which is accessible via tab navigation through the site, causing anyone using that style of navigation to have to press tab to navigate past a hidden element for each line of code in any given example. further reading on the issue
This an example of the offending HTML from the website produced by pandoc 2.9.2.1 in your CI image
This issue has been fixed by later versions of pandoc by including the tabindex="-1"
attribute on these a tags. I believe the fix lands in pandoc 2.11. pandoc release notes for 2.11 The fix is updating the skylight engine, where the actual fix occurred in their version 0.10. skylighting 0.10 changelog
This is what pandoc 2.17.1.1 produced for me when building it locally. image
This leads to an error:
$ diesel print-schema
unknown field `print-schema`, expected `print_schema`
Hey! Georg asked me to create a PR/issue for dsync here.
I tried to find a place on the website where a list of community projects might go but all I can think of is another section on the guides page. Let me know, and I can create a PR!
Although not outlined specifically by any OSHA or DOT regulations, the standard safety recommendation is to store diesel fuel in yellow containers. Red containers are reserved for gasoline fuel.
source
The link to dotenv
in the Getting Started Guide:
Returns a 404.
The dotenv
docs might be a better place to point.
Note that the dotenv
docs point to https://github.com/purpliminal/rust-dotenv/, which is currently intentionally empty (purpliminal/rust-dotenv#1), so pointing to the docs.rs may be a good solution until a GitHub repo is finalized.
Not sure if the solution to this is to show them on mobile, or just to have the examples non-tabbed on mobile. /cc @corwinharrell take a look at the bottom of the page on mobile.
Hey there,
Submitted a pull request here: #165, but getting the site built wasn't as straightforward as the README
currently suggests.
The first of my issues is that running make page
results in the following error:
ModuleNotFoundError: No module named 'pandocfilters'
. What the README
does not inform would-be contributors of is that the following prerequisites need to be met:
pandocfilters
module is installed globallyI would suggest updating the README
to let people know Python is required and subsequently looking into virtual environments to both version control the list of necessary packages, and enable modifying the Makefile
to instantiate the virtual environment before running the page
target.
I am assuming development has only happened on Linux machines, as after fixing the pandocfilters
issue, running make page
results in the following error:
cp assets/ out -r
cp: -r is not a directory
from this line in Makefile
.
cp
seems to behave differently on BSD/MacOS or something. I had to change the command to the following for the build to succeed:
cp -R assets out
So making sure this is a cross-platform compatible operation would be helpful. I believe this variation on the command works on both MacOS and Linux.
Hey there!
I am learning Rust and I am trying to create my own api based on actix-web
and diesel-orm
. I was going through Getting started
guide and while it had great examples for CRUD, it's missing an implementation for getting a single item from the database. I managed to find out how to do that in the end but it took me a while.
As preparation of the upcoming diesel 2.0 release we need to update the guides on our web page to reflect the corresponding changes.
For the "Getting Started" guide this involves the following points:
embed_migrations!
to the new syntax used therePlease use this issue as discussion platform to ask any question that is unclear about updating this guide.
On official guides the page Using Custom SQL and How to Extend the Query DSL, I found an error of document. See the following:
impl<T> Paginated<T> {
fn load_and_count_pages<U>(self, conn: &PgConnection) -> QueryResult<(Vec<U>, i64)
where
Self: LoadQuery<PgConnection, (U, i64)>,
{
let per_page = self.per_page;
let results = self.load::<(U, i64)>(conn)?;
let total = results.get(0).map(|(_, total) _total|).unwrap_or(0);
let records = results.into_iter().map(|(record, _)| record).collect();
let total_pages = (total as f64 / per_page as f64).ceil() as i64;
Ok((records, total_pages))
}
}
The seventh line of the sample code above should be:
let total = results.get(0).map(|(_, total)| _total).unwrap_or(0);
As preparation of the upcoming diesel 2.0 release we need to update the guides on our web page to reflect the corresponding changes.
For the "Extending diesel" guide this involves the following points:
diesel_*operator!
macros to use the non-deprecated diesel::*_operator!
variant.Please use this issue as discussion platform to ask any question that is unclear about updating this guide.
As preparation of the upcoming diesel 2.0 release we need to update the guides on our web page to reflect the corresponding changes.
For the "Configuring diesel cli" guide this involves the following points:
generate_missing_sql_type_definitions
option. This options allows users to control if diesel cli should generate sql type definitions for unknown types or not. This feature is currently only available for the postgres backend.patch
binary installed. Diesel cli now uses a built-in way to patch files.Please use this issue as discussion platform to ask any question that is unclear about updating this guide.
It would be nice to have this repo in the diesel-rs organization next to the rest of the diesel repositories. Currently it takes a little bit of searching to find out where the diesel.rs
website repo actually is.
it seems like with sqlite diesel traits its not queryable but execute work fine with my conn
.
let now = Utc::now().to_string();
let ne = NewEmployee {
name: &meta["Employee First Name and Last Name"].to_string().replace("\"", ""),
department: &"",
software_ids: &"",
created_on: &now,
created_by: & "ab-system",
updated_on: &now,
updated_by: & "ab-system",
};
diesel::insert_into(employee::table)
.values(ne)
.execute(conn)
.expect("Error saving new requestor");
// Get the ID of the last inserted row
let result = employee::dsl::employee.filter(updated_on.eq(now))
.get_result::<Employee>(conn).unwrap() <<<==== Here conn showing the above error
println!("{:#?}", result);
the traits are in order while insert_into.
Chrome now shows the URL as not secure
. This can be done with a click of a button. In github pages config
Is a schema required? I want to try deisel on a database that is maintained using ruby on rails.
I used a feature which is 0.16 only, but I used the 0.15 version. Got me confused.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.