Expand description

Diesel dynamic schema

Diesel is an ORM and query builder designed to reduce the boilerplate for database interactions.

If this is your first time reading about Diesel, then we recommend you start with the getting started guide. We also have many other long form guides.

Diesel is built to provide strong compile time guarantees that your queries are valid. To do this, it needs to represent your schema at compile time. However, there are some times where you don’t actually know the schema you’re interacting with until runtime.

This crate provides tools to work with those cases, while still being able to use Diesel’s query builder. Keep in mind that many compile time guarantees are lost. We cannot verify that the tables/columns you ask for actually exist, or that the types you state are correct.

Getting Started

The table function is used to create a new Diesel table. Note that you must always provide an explicit select clause when using this crate.

// Use diesel-dynamic-schema to create a table and columns.
let users = table("users");
let id = users.column::<Integer, _>("id");
let name = users.column::<Text, _>("name");

// Now you can use typical Diesel syntax; see the Diesel docs for more.
let results = users
    .select((id, name))
    .load::<(i32, String)>(conn)?;

for (id, name) in results {
    println!("id:{} name:{}", id, name);

See the /examples directory for runnable code examples.

Getting help

If you run into problems, Diesel has a very active Gitter room. You can come ask for help at gitter.im/diesel-rs/diesel


  • This module provides a container that allows to receive a dynamically specified number of fields from the database.


  • A database table column. A database table column. This type is created by the column function.
  • Represents a dynamically sized select clause
  • A database schema. A database schema. This type is created by the schema function.
  • A database table. A database table. This type is created by the table function.