sea-orm-dbml

Crates.iosea-orm-dbml
lib.rssea-orm-dbml
version0.1.0-beta.2
sourcesrc
created_at2023-01-20 09:03:35.43856
updated_at2023-05-07 09:47:08.465097
descriptionDBML to SeaORM entity compiler.
homepage
repositoryhttps://github.com/apskhem/sea-orm-dbml
max_upload_size
id763256
size79,223
Apisit Ritreungroj (apskhem)

documentation

README

SeaORM DBML

Database Markup Language (DBML) compiler for SeaORM Entity.

crate MSRV MIT or Apache 2.0 licensed unsafe forbidden

Why DBML?

DBML (Database Markup Language) is an open-source DSL language designed to define and document database schemas and structures. It is designed to be simple, consistent and highly-readable.

Read more: Official docs

This project aims to make use of DBML as a language for writing SeaORM entity.

Output

Below is the example of compiling DBML into SeaORM entity.

Table user {
  id integer [pk]
  username varchar
  role varchar
}
//! Generated by sea-orm-dbml 0.1.0

pub mod user {
  use sea_orm::entity::prelude::*;

  #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
  #[sea_orm(table_name = "user", schema_name = "public")]
  pub struct Model {
    #[sea_orm(column_type = "Integer", primary_key, auto_increment = false)]
    pub id: i32,
    #[sea_orm(column_type = "String(None)")]
    pub username: String,
    #[sea_orm(column_type = "String(None)")]
    pub role: String,
  }

  #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
  pub enum Relation {}

  impl ActiveModelBehavior for ActiveModel {}
}

How to use it?

use std::{ffi::OsString, error::Error};

use sea_orm_dbml::{compiler::config::Config, *};

fn main() -> Result<(), Box<dyn Error>> {
  compile(Config {
    in_path: OsString::from("path/to/file.dbml"),
    out_path: OsString::from("path/to/out/mod.rs"),
    target: compiler::config::Target::Postgres,
    ..Default::default()
  })
}

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Always welcome you to participate, contribute and together.

Commit count: 28

cargo fmt