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(())
}