Ormer
Home
Quick Start
GitHub
  • 简体中文
  • English
Home
Quick Start
GitHub
  • 简体中文
  • English
  • Introduction to Ormer
  • Quick Start
  • Model Definition
  • Database Connection
  • Data Operations
  • Query Builder
  • Advanced Queries
  • Transaction Management
  • Connection Pool

Database Connection

Supported Databases

  • Sqlite
  • PostgreSQL
  • MySQL
  • MSSQL

Enable Features

[dependencies]
ormer = { version = "0.1", features = ["sqlite"] }

Connection Strings

Sqlite:

  • Memory: :memory:
  • File: file:test.db
  • Remote: libsql://url.Sqlite.io?authToken=token

PostgreSQL:

  • postgresql://user:password@localhost/dbname

MySQL:

  • mysql://user:password@localhost/dbname

MSSQL:

  • mssql://user:password@localhost/dbname

Example

use ormer::{Database, DbType, Model};

#[derive(Debug, Model)]
#[table = "users"]
struct User {
    #[primary(auto)]
    id: i32,
    name: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db = Database::connect(DbType::Sqlite, "file:test.db").await?;
    db.create_table::<User>().execute().await?;
    db.drop_table::<User>().execute().await?;
    Ok(())
}
Last Updated: 6/4/26, 12:14 AM
Contributors: fawdlstty
Prev
Model Definition
Next
Data Operations