1#![allow(private_bounds, private_interfaces, clippy::type_complexity)]
2#![doc = include_str!("../README.md")]
3#![cfg_attr(not(docsrs), cfg(feature = "base0"))]
4#![cfg_attr(docsrs, feature(doc_cfg))]
5
6extern crate self as rust_query;
7
8#[macro_use]
9extern crate static_assertions;
10
11#[cfg(doc)]
12#[doc = include_str!("_guide.md")]
13pub mod _guide {}
14mod async_db;
16mod db;
17mod error;
18mod joinable;
19mod lazy;
20mod lower;
21mod migrate;
22mod mutable;
23#[cfg(feature = "__mutants")]
24mod mutants;
25mod pool;
26mod query;
27mod rows;
28mod schema;
29mod scoped_transaction;
30mod select;
31mod transaction;
32mod value;
33mod writable;
34
35use private::Reader;
36use schema::from_macro::TypBuilder;
37use std::fmt::Debug;
38use std::ops::Deref;
39
40pub use async_db::DatabaseAsync;
41pub use db::TableRow;
42pub use error::Conflict;
43pub use lazy::Lazy;
44pub use mutable::Mutable;
45pub use scoped_transaction::TransactionScope;
46pub use select::{IntoSelect, Select};
47pub use transaction::{Database, Transaction, TransactionWeak};
48pub use value::aggregate::aggregate;
49pub use value::from_expr::FromExpr;
50pub use value::{Expr, into_expr::IntoExpr, optional::optional};
51
52pub use rust_query_macros::Select;
106
107pub use rust_query_macros::FromExpr;
136
137use crate::error::FromConflict;
138
139pub mod args {
143 pub use crate::query::{OrderBy, Query};
144 pub use crate::rows::Rows;
145 pub use crate::value::aggregate::Aggregate;
146 pub use crate::value::optional::Optional;
147}
148
149pub mod migration {
153 pub use crate::migrate::{
154 Migrator,
155 config::{Config, ForeignKeys, Synchronous},
156 migration::{Migrated, MigratedOptional, TransactionMigrate},
157 };
158 #[cfg(feature = "dev")]
159 pub use crate::schema::dev::hash_schema;
160
161 #[doc = include_str!("schema/_schema.md")]
162 pub use rust_query_macros::schema;
163}
164
165#[doc(hidden)]
168pub mod private {
169
170 pub use crate::joinable::{IntoJoinable, Joinable};
171 pub use crate::migrate::{
172 Schema, SchemaMigration, TableTypBuilder,
173 migration::{Migrateable, SchemaBuilder},
174 with_test_renderer,
175 };
176 pub use crate::query::get_plan;
177 pub use crate::schema::from_macro::{SchemaType, TypBuilder};
178 pub use crate::schema::tokenizer::{Token, get_token};
179 pub use crate::value::{DbTyp, adhoc_expr, new_column, unique_from_joinable};
180 pub use crate::writable::Reader;
181
182 pub mod doctest_aggregate {
202 #[crate::migration::schema(M)]
203 pub mod vN {
204 pub struct Val {
205 pub x: i64,
206 }
207 }
208 pub use crate::aggregate;
209 pub use v0::*;
210
211 #[cfg_attr(false, mutants::skip)]
212 pub fn get_txn(f: impl Send + FnOnce(&mut crate::Transaction<M>)) {
213 crate::Database::new(rust_query::migration::Config::open_in_memory())
214 .transaction_mut_ok(f)
215 }
216 }
217
218 pub mod doctest {
219 use crate::{Database, Transaction, migrate::config::Config, migration};
220
221 #[migration::schema(Empty)]
222 pub mod vN {
223 pub struct User {
224 #[unique]
225 pub name: String,
226 }
227 }
228 pub use v0::*;
229
230 #[cfg_attr(false, mutants::skip)]
231 pub fn get_txn(f: impl Send + FnOnce(&'static mut Transaction<Empty>)) {
232 let db = Database::new(Config::open_in_memory());
233 db.transaction_mut_ok(|txn| {
234 txn.insert(User {
235 name: "Alice".to_owned(),
236 })
237 .unwrap();
238 f(txn)
239 })
240 }
241 }
242}
243
244pub trait Table: Sized + 'static {
248 #[doc(hidden)]
249 type Ext2<'t>;
250
251 #[doc(hidden)]
252 fn covariant_ext<'x, 't>(val: &'x Self::Ext2<'static>) -> &'x Self::Ext2<'t>;
253
254 #[doc(hidden)]
255 fn build_ext2<'t>(val: &Expr<'t, Self::Schema, TableRow<Self>>) -> Self::Ext2<'t>;
256
257 type Schema;
259
260 #[doc(hidden)]
261 type MigrateFrom: Table;
263
264 type Conflict: FromConflict + Debug;
267 type Referer;
269
270 #[doc(hidden)]
271 type Mutable: Deref;
272 #[doc(hidden)]
273 type Lazy<'t>;
274
275 #[doc(hidden)]
276 fn read(&self, f: &mut Reader);
277
278 #[doc(hidden)]
279 type Select;
280
281 #[doc(hidden)]
282 fn into_select(
283 val: Expr<'_, Self::Schema, TableRow<Self>>,
284 ) -> Select<'_, Self::Schema, Self::Select>;
285
286 #[doc(hidden)]
287 fn select_mutable(select: Self::Select) -> Self::Mutable;
288
289 #[doc(hidden)]
290 fn select_lazy<'t>(select: Self::Select) -> Self::Lazy<'t>;
291
292 #[doc(hidden)]
293 fn mutable_as_unique(val: &mut Self::Mutable) -> &mut <Self::Mutable as Deref>::Target;
294
295 #[doc(hidden)]
296 fn mutable_into_insert(val: Self::Mutable) -> Self
297 where
298 Self: Sized;
299
300 #[doc(hidden)]
301 fn get_referer_unchecked() -> Self::Referer;
302
303 #[doc(hidden)]
304 fn typs(f: &mut TypBuilder<Self::Schema>);
305
306 #[doc(hidden)]
307 const SPAN: (usize, usize);
308
309 #[doc(hidden)]
310 const ID: &'static str;
311 #[doc(hidden)]
312 const NAME: &'static str;
313}
314
315#[test]
316#[cfg(feature = "jiff-02")]
317fn compile_tests() {
318 let t = trybuild::TestCases::new();
319 t.compile_fail("tests/compile/*.rs");
320}