1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//!
//! <div align="center">
//! <img src="https://raw.githubusercontent.com/weldsorm/welds/main/page/src/assets/images/banner.png"/>
//! <h3>An async ORM written in rust using sqlx and/or Tiberius.</h3>
//! </div>
//!
//! # What is Welds
//! Welds is an ORM for the Rust programming language.
//! The primary way to interact with Welds is by adding the "welds" macros to your structs.
//! This adds to your structs Welds functions and allows for great autocompletion and very intuitive code.
//!
//! # Macros - Setup your structs
//!
//! To add welds to your struct you will need to derive `welds::WeldsModel`
//! ```rust,ignore
//! #[derive(welds::WeldsModel)]
//! ```
//!
//! ## Connect to table / view
//! Let welds know what DB table/schema it will be reading/writing data from
//! ```rust,ignore
//! #[welds(schema = "public", table = "products")]
//! ```
//! if you don't want to allow writing to the table you can add readonly. (useful for views)
//! ```rust,ignore
//! #[welds(readonly)]
//! ```
//!
//! ## Build Relations for Joining
//! You can write queries that join across tables if you Wireup welds with relationships
//!
//! Welds Supports:
//! - BelongsTo
//! - HasOne
//! - HasMany
//!
//! They are both in the format:
//! ```rust,ignore
//! [field, rust_path_to_other_object, "str_of_foreign_key_column"]
//! ```
//! NOTE: Both `BelongsTo` and `HasMany` need to know the foreign_key column
//!
//! If you are working on a struct that has a foreign_key to another table use a `BelongsTo`
//!
//! ```rust,ignore
//! #[welds(BelongsTo(product, super::product::product_id, "product_id"))]
//! struct Order {
//! product_id: ...,
//! ...,
//! }
//! ```
//!
//! If you are working on a struct that has a foreign_key pointed at it, use a `HasMany`
//! ```rust,ignore
//! #[welds(HasMany(orders, super::order::Order, "product_id"))]
//! struct Product {
//! ...,
//! }
//! ```
//!
//! If working with a many-to-many relationship, add a `HasMany` on both structs, and add two `BelongsTo`
//! on the join table struct
//! ```rust,ignore
//! #[welds(BelongsTo(order, super::order::Order, "order_id"))]
//! #[welds(BelongsTo(product, super::product::Product, "product_id"))]
//! struct ProductOrders {
//! #[welds(primary_key)]
//! id: i32,
//! order_id: i32,
//! product_id: i32,
//! }
//! ```
//!
//! ## Fields Level Attributes
//! There are a couple attributes you can add to your fields to help control how welds functions
//! - `#[welds(primary_key)]` Important! Add this to the primary key of your table.
//! - `#[welds(rename = "xyz")]` let welds know the underlying column has a different name than the field
//! - `#[welds(ignore)]` Tell welds this field is it not in the database.
//!
//!
//! ## Putting it all together
//! Here is a working example of what a fully setup struct might look like
//! ```rust,ignore
//! #[derive(Debug, welds::WeldsModel)]
//! #[welds(schema = "public", table = "products")]
//! #[welds(HasMany(order, super::order::Order, "product_id"))]
//! pub struct Product {
//! #[welds(primary_key)]
//! #[welds(rename = "product_id")]
//! pub id: i32,
//! pub active: Option<bool>,
//! pub description: Option<String>,
//! pub name: String,
//! }
//! ```
//!
//! # Using Welds
//!
//! When WeldsModel is added to your struct the following is added directly to your model
//!
//! - [`Model::new()`]( ./state/struct.DbState.html#method.new_uncreated ) make a new model ready to be saved to the database
//! - `Model::find_by_id()`
//! - [`Model::all()`](./query/builder/struct.QueryBuilder.html) start a query for a Model
//! - [`Model::where_col()`](./query/builder/struct.QueryBuilder.html) start a query for a Model
//! - `Model::from_raw_sql()` finds Model using raw custom SQL str
//!
//! Instances of your model are wrapped in a [welds::state::DbState](./state/struct.DbState.html).
//! From your instance you can update, create, and delete.
//!
//! Start a query from the struct that derived WeldsModel
//! ```rust,ignore
//! let client = welds::connections::postgres::connect(&url).await.unwrap();
//! let sellers = Product::all()
//! .where_col(|product| product.price.equal(3.50))
//! .map_query(|product| product.seller )
//! .where_col(|seller| seller.name.ilike("%Nessie%") )
//! .order_by_desc(|seller| seller.id )
//! .limit( 10 )
//! .run(&client).await?;
//!
//! ```
//!
//! For more examples on how to use Welds check out the [Example Repo](https://github.com/weldsorm/welds/tree/main/welds/examples)
//!
//! ## Examples:
//! - [Basic CRUD](https://github.com/weldsorm/welds/blob/main/welds/examples/crud.rs)
//! - [Mapping Queries / Joining](https://github.com/weldsorm/welds/blob/main/welds/examples/crud.rs)
//! - [Bulk (Create/Update/Delete)](https://github.com/weldsorm/welds/blob/main/welds/examples/bulk_operations.rs)
//! - [Select Only Specific Columns](https://github.com/weldsorm/welds/blob/main/welds/examples/manual_select_columns.rs)
//! - [Hooks, Callback when models (Save/Update/Delete)](https://github.com/weldsorm/welds/blob/main/welds/examples/hooks.rs)
//! - [Scopes for your Models](https://github.com/weldsorm/welds/blob/main/welds/examples/scopes.rs)
//! - [Migrations](https://github.com/weldsorm/welds/blob/main/welds/examples/migrations.rs)
//! - [Checking DB schema matches compiled structs](https://github.com/weldsorm/welds/blob/main/welds/examples/verify_tables.rs)
//
//!
//! # Features
//!
//! - postgres - enables postgres database connection. (requires sqlx setup)
//! - mysql - enables MySql database connection. (requires sqlx setup)
//! - sqlite - enables Sqlite database connection. (requires sqlx setup)
//! - mssql - enables Microsoft SQL support. (requires tokio runtime.)
//! - detect - enables scanning of the database to get schema info
//! - check - enables checking your models against table in the database
//! - migrations - adds all the migration structs and traits
//! - full - all the features excluding (mock)
//! - mock - Use for testing ONLY. Enables mocking out database schemas
//! - group-by - Enables use of group_by and aggregate functions
//!
//!
//! # Important Notes:
//!
//! - If you are using one of the `sqlx` connections, you will need to setup sqlx. This is so you can pick an async runtime.
//!
pub use WeldsError;
pub use welds_connections as connections;
/// Re-export welds_connections
pub use StreamClient;
pub use ;
/// Re-export the Macro used to make models
pub use WeldsModel;