Installation

Add tideorm to your Cargo.toml with one backend feature and one runtime feature, and add the async runtime itself:

[dependencies]
tideorm = { version = "0.18.2", default-features = false, features = ["postgres", "runtime-tokio"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

That is all a project needs to define models and run queries; serde, chrono and serde_json come through tideorm and its prelude. The Quick Start builds a complete program on it.

The dependency may be renamed (orm = { package = "tideorm", .. }, then #[orm::model]): the macros read the name from the crate's Cargo.toml, [workspace.dependencies] included. A crate that defines models must depend on tideorm itself, under whatever name; a re-export through another crate is not enough.

Choosing a Backend

Each backend is a Cargo feature that builds its driver:

# PostgreSQL
tideorm = { version = "0.18.2", default-features = false, features = ["postgres", "runtime-tokio"] }

# MySQL or MariaDB
tideorm = { version = "0.18.2", default-features = false, features = ["mysql", "runtime-tokio"] }

# SQLite
tideorm = { version = "0.18.2", default-features = false, features = ["sqlite", "runtime-tokio"] }

The default feature set is ["postgres", "runtime-tokio"]. Set default-features = false and name your features explicitly: a MySQL- or SQLite-only project that leaves the defaults on still compiles the whole PostgreSQL driver.

Backend features add to each other. With several enabled, the connection URL picks the backend at runtime (see Databases), so one binary can talk to PostgreSQL and SQLite at once. A URL for a backend whose feature is not compiled in is refused with a configuration error that names the feature to enable.

FeatureBuildsUse it for
postgresThe PostgreSQL driverPostgreSQL
mysqlThe MySQL driverMySQL and MariaDB
sqliteThe SQLite driver, with a bundled SQLite (3.46 or later)SQLite; no system library is needed
mariadb, tidb, vitessThe same as mysqlNaming the server you run in your manifest
cockroachdb, yugabytedbThe same as postgresNaming the server you run in your manifest

The server-named features are aliases: features = ["cockroachdb"] and features = ["postgres"] build the same code. Compatible Servers lists what differs on each server.

Choosing a Runtime

FeatureRuntime
runtime-tokioTokio (default)
runtime-async-stdasync-std

Enable one, and add that runtime to your own dependencies so you can start it (#[tokio::main], #[async_std::main]).

Optional Modules

Six features unlock optional APIs. They add no dependencies; they only make the API visible:

FeatureUnlocks
attachmentsFile attachments on models (HasAttachments, tideorm::attachments); see File Attachments
translationsTranslated fields (HasTranslations, ApplyTranslations, tideorm::translations); see Translations
fulltextFull-text search and highlighting (tideorm::fulltext); see Full-Text Search
entity-managerThe EntityManager persistence context: an identity map, find, find_managed, load, save, persist, merge, remove, detach and flush; see Entity Manager
dirty-trackingchanged_fields() and original_value() on models; see Reading and Writing
encrypted-fields#[tideorm(encrypted = "..")] columns, encrypted on write and decrypted on load; see Encrypted Fields
tideorm = { version = "0.18.2", default-features = false, features = ["postgres", "runtime-tokio", "fulltext", "entity-manager"] }

Each page for a feature-gated API names its feature at the top.

What Else Your Crate Needs

Nothing, for the models themselves. The code #[tideorm::model] generates reaches serde, serde_json and chrono through TideORM, and tideorm::prelude re-exports the types models usually hold: DateTime, Utc, NaiveDate, NaiveDateTime, NaiveTime, Decimal, Uuid and JsonValue.

Add a dependency only when your own code needs it:

  • serde, if your own code derives Serialize or Deserialize.
  • chrono, if you spell a type with an explicit chrono:: path.

Supported Rust Versions

TideORM needs Rust 1.94 or later. Every TideORM crate (the macros, the engine, the SQL builder and the drivers) declares rust-version = "1.94", and CI checks the library with that toolchain. To build with it explicitly, run cargo +1.94.0 build.

The CLI

The TideORM CLI is a separate crate whose binary is named tideorm. It scaffolds projects (tideorm init), generates models, migrations and seeders, and runs migrations and seeders through your project's own code. You do not need it to use the library.