#![allow(private_bounds, private_interfaces)]
#![doc = include_str!("../README.md")]
#![cfg_attr(not(docsrs), cfg(feature = "base0"))]
#![cfg_attr(docsrs, feature(doc_cfg))]
extern crate self as rust_query;
#[macro_use]
extern crate static_assertions;
#[cfg(doc)]
#[doc = include_str!("_guide.md")]
pub mod _guide {}
mod async_db;
mod db;
mod error;
mod joinable;
mod lazy;
mod lower;
mod migrate;
mod mutable;
#[cfg(feature = "mutants")]
mod mutants;
mod pool;
mod query;
mod rows;
mod schema;
mod select;
mod transaction;
mod value;
mod writable;
use private::Reader;
use schema::from_macro::TypBuilder;
use std::ops::Deref;
pub use async_db::DatabaseAsync;
pub use db::TableRow;
pub use error::Conflict;
pub use lazy::Lazy;
pub use mutable::Mutable;
pub use select::{IntoSelect, Select};
pub use transaction::{Database, Transaction, TransactionWeak};
pub use value::aggregate::aggregate;
pub use value::from_expr::FromExpr;
pub use value::{Expr, into_expr::IntoExpr, optional::optional};
pub use rust_query_macros::Select;
pub use rust_query_macros::FromExpr;
use crate::error::FromConflict;
pub mod args {
pub use crate::query::{OrderBy, Query};
pub use crate::rows::Rows;
pub use crate::value::aggregate::Aggregate;
pub use crate::value::optional::Optional;
}
pub mod migration {
pub use crate::migrate::{
Migrator,
config::{Config, ForeignKeys, Synchronous},
migration::{Migrated, TransactionMigrate},
};
#[cfg(feature = "dev")]
pub use crate::schema::dev::hash_schema;
pub use rust_query_macros::schema;
}
#[doc(hidden)]
pub mod private {
pub use crate::joinable::{IntoJoinable, Joinable};
pub use crate::migrate::{
Schema, SchemaMigration, TableTypBuilder,
migration::{Migration, SchemaBuilder},
};
pub use crate::query::get_plan;
pub use crate::schema::from_macro::{SchemaType, TypBuilder};
pub use crate::schema::tokenizer::{Token, get_token};
pub use crate::value::{DbTyp, adhoc_expr, new_column, unique_from_joinable};
pub use crate::writable::Reader;
pub mod doctest_aggregate {
#[crate::migration::schema(M)]
pub mod vN {
pub struct Val {
pub x: i64,
}
}
pub use crate::aggregate;
pub use v0::*;
#[cfg_attr(test, mutants::skip)]
pub fn get_txn(f: impl Send + FnOnce(&'static mut crate::Transaction<M>)) {
crate::Database::new(rust_query::migration::Config::open_in_memory())
.transaction_mut_ok(f)
}
}
pub mod doctest {
use crate::{Database, Transaction, migrate::config::Config, migration};
#[migration::schema(Empty)]
pub mod vN {
pub struct User {
#[unique]
pub name: String,
}
}
pub use v0::*;
#[cfg_attr(test, mutants::skip)]
pub fn get_txn(f: impl Send + FnOnce(&'static mut Transaction<Empty>)) {
let db = Database::new(Config::open_in_memory());
db.transaction_mut_ok(|txn| {
txn.insert(User {
name: "Alice".to_owned(),
})
.unwrap();
f(txn)
})
}
}
}
pub trait Table: Sized + 'static {
#[doc(hidden)]
type Ext2<'t>;
#[doc(hidden)]
fn covariant_ext<'x, 't>(val: &'x Self::Ext2<'static>) -> &'x Self::Ext2<'t>;
#[doc(hidden)]
fn build_ext2<'t>(val: &Expr<'t, Self::Schema, TableRow<Self>>) -> Self::Ext2<'t>;
type Schema;
#[doc(hidden)]
type MigrateFrom: Table;
type Conflict: FromConflict;
type Referer;
#[doc(hidden)]
type Mutable: Deref;
#[doc(hidden)]
type Lazy<'t>;
#[doc(hidden)]
fn read(&self, f: &mut Reader);
#[doc(hidden)]
type Select;
#[doc(hidden)]
fn into_select(
val: Expr<'_, Self::Schema, TableRow<Self>>,
) -> Select<'_, Self::Schema, Self::Select>;
#[doc(hidden)]
fn select_mutable(select: Self::Select) -> Self::Mutable;
#[doc(hidden)]
fn select_lazy<'t>(select: Self::Select) -> Self::Lazy<'t>;
#[doc(hidden)]
fn mutable_as_unique(val: &mut Self::Mutable) -> &mut <Self::Mutable as Deref>::Target;
#[doc(hidden)]
fn mutable_into_insert(val: Self::Mutable) -> Self
where
Self: Sized;
#[doc(hidden)]
fn get_referer_unchecked() -> Self::Referer;
#[doc(hidden)]
fn typs(f: &mut TypBuilder<Self::Schema>);
#[doc(hidden)]
const SPAN: (usize, usize);
#[doc(hidden)]
const ID: &'static str;
#[doc(hidden)]
const NAME: &'static str;
}
trait CustomJoin: Table {
fn name(&self) -> lower::JoinableTable;
fn main_column(&self) -> &'static str;
}
#[test]
#[cfg(feature = "jiff-02")]
fn compile_tests() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/compile/*.rs");
}