Expand description
An experimental ORM for Rust with a focus on simplicity and on writing Rust, not SQL Butane takes an object-oriented approach to database operations. It may be thought of as much as an object-persistence system as an ORM. The fact that it is backed by a SQL database is mostly an implementation detail to the API consumer.
Modules§
- custom
- For supporting additional types with the Pg backend (or other future backends).
- db
- Types, traits, and methods for interacting with a database.
- internal
- Internals used in macro-generated code.
- migrations
- For working with migrations. If using the butane CLI tool, it is not necessary to use these types directly.
- prelude
- Prelude module to improve ergonomics. Brings certain traits into scope.
This module is for sync operation. For asynchronous, see
super::prelude_async. - prelude_
async - Prelude module to improve ergonomics in async operation. Brings certain traits into scope.
- query
- Types to support database queries. Most users will use
the
query!,filter!, andfind!macros instead of using this module directly.
Macros§
- colname
- Type-safe way to refer to a column name. Use as
colname!(MODEL_TYPE, FIELD_NAME). E.g. For a model typeFoowith a fieldbar,colname!(Foo, bar) would return“bar”, butcolname!(Foo, bat)would be a compiler error (assumingFoo` does not have such a field. - filter
- Macro to construct a
BoolExpr(for use with aQuery) from an expression with Rust syntax. - find
- Finds a specific database object.
- find_
async - Like
find, but for async. - query
- Constructs a filtered database query.
Structs§
- AutoPk
- Wrapper around a PrimaryKeyType to indicate the the primary key
will be initialized automatically when the object is created in
the database.
Dereferences to an
Option<T>. - Foreign
Key - Used to implement a relationship between models.
- Many
- Used to implement a many-to-many relationship between models.
Enums§
- Error
- Butane errors.
- SqlType
- Enumeration of the types a database value may take.
- SqlVal
- A database value.
- SqlVal
Ref
Traits§
- AsPrimary
Key - Trait for referencing the primary key for a given model. Used to implement ForeignKey equality tests.
- Data
Object - An object in the database.
- Data
Object OpsAsync DataObjectoperations that require a live database connection.- Data
Object OpsSync DataObjectoperations that require a live database connection.- Data
Result - A type which may be the result of a database query.
- Field
Type - Type suitable for being a database column.
- Foreign
KeyOps Async ForeignKeyoperations which require aConnection.- Foreign
KeyOps Sync ForeignKeyoperations which require aConnection.- FromSql
- Used to convert a
SqlValorSqlValRefinto another type. - Many
OpsAsync Manyoperations which require aConnection.- Many
OpsSync Manyoperations which require aConnection.- Primary
KeyType - Marker trait for a type suitable for being a primary key
- ToSql
- Used to convert another type to a
SqlValorSqlValRef.
Type Aliases§
- Result
- Result type that uses
crate::Error.
Attribute Macros§
- butane_
type - Attribute macro which marks a type as being available to butane for use in models.
- dataresult
- Attribute macro which generates an implementation of
DataResult. Continuing with our blog post example from model, we could create aDataResultwith only some of the fields fromPost(to avoid fetching all of them in a query). - model
- Attribute macro which marks a struct as being a data model and
generates an implementation of
DataObject. This macro will also write information to disk at compile time necessary to generate migrations
Derive Macros§
- Field
Type - Derive macro for
FieldType. Produces a String field for simple enums, otherwise uses a JSON field if json feature is enabled. E.g. - Primary
KeyType - Derive macro for marker trait
PrimaryKeyType. E.g.