Declaring the data structure

Our tool will have two modules with a data structure. The first is the src/schema.rs module, which contains a table! macro call that declares the fields of every table. In our case, this module contains the following declaration:

table! {
users (id) {
id -> Text,
name -> Text,
email -> Text,
}
}

This file was automatically generated by the diesel setup command. When you run a setup, it creates a diesel.toml configuration file with the following contents:

# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"

As you can see, the config has a schema module reference. A schema.rs file is also generated, and will be updated on every compilation. The table! macro creates the required declaration of DSL for the tables used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.63.95