Skip to main content

prax_import/
lib.rs

1//! # prax-import
2//!
3//! Import schemas from Prisma, Diesel, and SeaORM to Prax ORM.
4//!
5//! This crate provides utilities to migrate existing Prisma, Diesel, and SeaORM schemas
6//! to Prax's schema format, making it easy to switch ORMs or start using Prax
7//! in existing projects.
8//!
9//! ## Features
10//!
11//! - **Prisma Import**: Parse Prisma schema files (`.prisma`) and convert to Prax
12//! - **Diesel Import**: Parse Diesel schema files (Rust code with `table!` macros) and convert to Prax
13//! - **SeaORM Import**: Parse SeaORM entity files (Rust code with `DeriveEntityModel`) and convert to Prax
14//! - **Type Mapping**: Automatic conversion of types between ORMs
15//! - **Relation Mapping**: Preserve relations and foreign keys
16//! - **Attribute Mapping**: Convert attributes and constraints
17//!
18//! ## Quick Start
19//!
20//! ### Import from Prisma
21//!
22//! ```rust,no_run
23//! use prax_import::prisma::import_prisma_schema;
24//!
25//! let prisma_schema = r#"
26//! model User {
27//!   id        Int      @id @default(autoincrement())
28//!   email     String   @unique
29//!   name      String?
30//!   posts     Post[]
31//!   createdAt DateTime @default(now())
32//! }
33//!
34//! model Post {
35//!   id        Int      @id @default(autoincrement())
36//!   title     String
37//!   content   String?
38//!   published Boolean  @default(false)
39//!   authorId  Int
40//!   author    User     @relation(fields: [authorId], references: [id])
41//! }
42//! "#;
43//!
44//! let prax_schema = import_prisma_schema(prisma_schema).unwrap();
45//! println!("Converted {} models", prax_schema.models.len());
46//! ```
47//!
48//! ### Import from Diesel
49//!
50//! ```rust,no_run
51//! use prax_import::diesel::import_diesel_schema;
52//!
53//! let diesel_schema = r#"
54//! table! {
55//!     users (id) {
56//!         id -> Int4,
57//!         email -> Varchar,
58//!         name -> Nullable<Varchar>,
59//!         created_at -> Timestamp,
60//!     }
61//! }
62//!
63//! table! {
64//!     posts (id) {
65//!         id -> Int4,
66//!         title -> Varchar,
67//!         content -> Nullable<Text>,
68//!         published -> Bool,
69//!         author_id -> Int4,
70//!     }
71//! }
72//!
73//! joinable!(posts -> users (author_id));
74//! "#;
75//!
76//! let prax_schema = import_diesel_schema(diesel_schema).unwrap();
77//! println!("Converted {} models", prax_schema.models.len());
78//! ```
79//!
80//! ### Import from SeaORM
81//!
82//! ```rust,no_run
83//! use prax_import::seaorm::import_seaorm_entity;
84//!
85//! let seaorm_entity = r#"
86//! use sea_orm::entity::prelude::*;
87//!
88//! #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
89//! #[sea_orm(table_name = "users")]
90//! pub struct Model {
91//!     #[sea_orm(primary_key, auto_increment)]
92//!     pub id: i32,
93//!     pub email: String,
94//!     pub name: Option<String>,
95//! }
96//!
97//! #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
98//! pub enum Relation {}
99//! "#;
100//!
101//! let prax_schema = import_seaorm_entity(seaorm_entity).unwrap();
102//! println!("Converted {} models", prax_schema.models.len());
103//! ```
104//!
105//! ## Type Mappings
106//!
107//! ### Prisma to Prax
108//!
109//! | Prisma Type | Prax Type |
110//! |-------------|-----------|
111//! | `Int` | `Int` |
112//! | `BigInt` | `BigInt` |
113//! | `Float` | `Float` |
114//! | `Decimal` | `Decimal` |
115//! | `String` | `String` |
116//! | `Boolean` | `Boolean` |
117//! | `DateTime` | `DateTime` |
118//! | `Json` | `Json` |
119//! | `Bytes` | `Bytes` |
120//!
121//! ### Diesel to Prax
122//!
123//! | Diesel Type | Prax Type |
124//! |-------------|-----------|
125//! | `Int4` | `Int` |
126//! | `Int8` | `BigInt` |
127//! | `Float4` / `Float8` | `Float` |
128//! | `Numeric` | `Decimal` |
129//! | `Varchar` / `Text` | `String` |
130//! | `Bool` | `Boolean` |
131//! | `Timestamp` | `DateTime` |
132//! | `Json` / `Jsonb` | `Json` |
133//! | `Bytea` | `Bytes` |
134
135pub mod error;
136
137#[cfg(feature = "prisma")]
138pub mod prisma;
139
140#[cfg(feature = "diesel")]
141pub mod diesel;
142
143#[cfg(feature = "seaorm")]
144pub mod seaorm;
145
146mod converter;
147
148pub use error::{ImportError, ImportResult};
149
150/// Prelude module for convenient imports.
151pub mod prelude {
152    pub use crate::error::{ImportError, ImportResult};
153
154    #[cfg(feature = "prisma")]
155    pub use crate::prisma::{import_prisma_schema, import_prisma_schema_file};
156
157    #[cfg(feature = "diesel")]
158    pub use crate::diesel::{import_diesel_schema, import_diesel_schema_file};
159
160    #[cfg(feature = "seaorm")]
161    pub use crate::seaorm::{import_seaorm_entity, import_seaorm_entity_file};
162}