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
//! Queries as data, and everything that turns them into statements.
//!
//! A [`Query`] is one filter, order, page, selection, aggregate, join or
//! union, as data: built in code (`Query::equal(...)`) or parsed from the
//! JSON clients send ([`Query::parse`]). Builders compile lists of queries
//! into statements for MySQL, MariaDB, PostgreSQL, SQLite, ClickHouse and
//! MongoDB ([`builder`]), with parameter bindings, joins, aggregates,
//! window functions, upserts and dialect features. Schema builders write
//! DDL ([`schema`]). A SQL tokenizer ([`tokenizer`]), parser and serializer
//! ([`ast`]) and a statement classifier ([`classifier`]) read SQL back.
//!
//! Values are PHP values ([`Value`], from `php-std`): queries and statements
//! are shared with PHP, so integers stay distinct from floats and arrays
//! keep their keys and order.
//!
//! PHP: ports `utopia-php/query`.
//!
//! | PHP | Rust |
//! |---|---|
//! | `Query` | [`Query`] |
//! | `Method` | [`Method`] |
//! | `Type`, `CursorDirection`, `OrderDirection`, `NullsPosition` | [`Type`], [`CursorDirection`], [`OrderDirection`], [`NullsPosition`] |
//! | `Compiler` | [`Compiler`] |
//! | `QuotesIdentifiers` | [`quote`], [`quote_literal`] |
//! | `Builder\ParsedQuery` | [`ParsedQuery`] |
//! | `Exception`, `Exception\ValidationException`, `Exception\UnsupportedException` | [`Error::Query`], [`Error::Validation`], [`Error::Unsupported`] |
//! | `Builder\*` | [`builder`] |
//! | `Hook\*` | [`hook`] |
//! | `Schema\*` | [`schema`] |
//! | `Tokenizer\*` | [`tokenizer`] |
//! | `AST\*` | [`ast`] |
//! | `Classifier\*` | [`classifier`] |
//!
//! ```
//! use utopia_query::Query;
//! use utopia_query::builder::MySql;
//!
//! let statement = MySql::new()
//! .from("users", "")
//! .select(["name", "email"])
//! .filter([Query::equal("status", ["active"]), Query::greater_than("age", 18)])
//! .limit(25)
//! .build()?;
//! assert_eq!(statement.query, "SELECT `name`, `email` FROM `users` WHERE `status` IN (?) AND `age` > ? LIMIT ?");
//! # Ok::<(), utopia_query::Error>(())
//! ```
//!
//! ```php
//! use Utopia\Query\Builder\MySQL;
//! use Utopia\Query\Query;
//!
//! $statement = (new MySQL())
//! ->from('users')
//! ->select(['name', 'email'])
//! ->filter([Query::equal('status', ['active']), Query::greaterThan('age', 18)])
//! ->limit(25)
//! ->build();
//! echo $statement->query, "\n"; // SELECT `name`, `email` FROM `users` WHERE `status` IN (?) AND `age` > ? LIMIT ?
//! ```
pub use ;
pub use ;
pub use StringLiteral;
pub use Method;
pub use ;
pub use ;
pub use ;
/// The getting started guide (`guide.md`), compiled and run with the doctests.
;