Skip to content

Commit a6cdd82

Browse files
committed
chore: more fixes, more docs
1 parent de82f60 commit a6cdd82

File tree

7 files changed

+28
-27
lines changed

7 files changed

+28
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flareon-cli/src/migration_generator.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl MigrationGenerator {
120120
migration.toposort_operations();
121121
migration
122122
.dependencies
123-
.extend(migration.get_foreign_key_dependencies(&self.crate_name));
123+
.extend(migration.get_foreign_key_dependencies());
124124

125125
Ok(Some(migration))
126126
}
@@ -527,7 +527,7 @@ pub struct SourceFile {
527527

528528
impl SourceFile {
529529
#[must_use]
530-
pub fn new(path: PathBuf, content: syn::File) -> Self {
530+
fn new(path: PathBuf, content: syn::File) -> Self {
531531
assert!(
532532
path.is_relative(),
533533
"path must be relative to the src directory"
@@ -666,7 +666,7 @@ pub struct GeneratedMigration {
666666
}
667667

668668
impl GeneratedMigration {
669-
fn get_foreign_key_dependencies(&self, crate_name: &str) -> Vec<DynDependency> {
669+
fn get_foreign_key_dependencies(&self) -> Vec<DynDependency> {
670670
let create_ops = self.get_create_ops_map();
671671
let ops_adding_foreign_keys = self.get_ops_adding_foreign_keys();
672672

@@ -977,20 +977,8 @@ impl Repr for DynOperation {
977977
fn repr(&self) -> TokenStream {
978978
match self {
979979
Self::CreateModel {
980-
table_name,
981-
model_ty,
982-
fields,
983-
..
980+
table_name, fields, ..
984981
} => {
985-
let model_name = match model_ty {
986-
syn::Type::Path(syn::TypePath { path, .. }) => path
987-
.segments
988-
.last()
989-
.expect("TypePath must have at least one segment")
990-
.ident
991-
.to_string(),
992-
_ => unreachable!("model_ty is expected to be a TypePath"),
993-
};
994982
let fields = fields.iter().map(Repr::repr).collect::<Vec<_>>();
995983
quote! {
996984
::flareon::db::migrations::Operation::create_model()
@@ -1265,7 +1253,7 @@ mod tests {
12651253
}],
12661254
};
12671255

1268-
let external_dependencies = migration.get_foreign_key_dependencies("my_crate");
1256+
let external_dependencies = migration.get_foreign_key_dependencies();
12691257
assert!(external_dependencies.is_empty());
12701258
}
12711259

@@ -1292,7 +1280,7 @@ mod tests {
12921280
}],
12931281
};
12941282

1295-
let external_dependencies = migration.get_foreign_key_dependencies("my_crate");
1283+
let external_dependencies = migration.get_foreign_key_dependencies();
12961284
assert_eq!(external_dependencies.len(), 1);
12971285
assert_eq!(
12981286
external_dependencies[0],
@@ -1342,7 +1330,7 @@ mod tests {
13421330
],
13431331
};
13441332

1345-
let external_dependencies = migration.get_foreign_key_dependencies("my_crate");
1333+
let external_dependencies = migration.get_foreign_key_dependencies();
13461334
assert_eq!(external_dependencies.len(), 2);
13471335
assert!(external_dependencies.contains(&DynDependency::Model {
13481336
model_type: parse_quote!(my_crate::Table2),

flareon/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ time.workspace = true
4646
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
4747
tower = { workspace = true, features = ["util"] }
4848
tower-sessions = { workspace = true, features = ["memory-store"] }
49-
env_logger = "0.11.5"
5049

5150
[dev-dependencies]
5251
async-stream.workspace = true

flareon/src/auth.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ use subtle::ConstantTimeEq;
2323
use thiserror::Error;
2424

2525
use crate::config::SecretKey;
26-
use crate::db::DbValue;
2726
#[cfg(feature = "db")]
28-
use crate::db::{ColumnType, DatabaseField, FromDbValue, SqlxValueRef, ToDbValue};
27+
use crate::db::{ColumnType, DatabaseField, DbValue, FromDbValue, SqlxValueRef, ToDbValue};
2928
use crate::request::{Request, RequestExt};
3029

3130
#[derive(Debug, Error)]

flareon/src/db.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl DatabaseError {
7373
}
7474
}
7575

76+
/// An alias for [`Result`] that uses [`DatabaseError`] as the error type.
7677
pub type Result<T> = std::result::Result<T, DatabaseError>;
7778

7879
/// A model trait for database models.
@@ -211,6 +212,8 @@ impl Column {
211212
}
212213
}
213214

215+
/// A marker trait that denotes that a type can be used as a primary key in a
216+
/// database.
214217
pub trait PrimaryKey: DatabaseField + Clone {}
215218

216219
/// A row structure that holds the data of a single row retrieved from the
@@ -749,7 +752,11 @@ impl Database {
749752

750753
fn supports_returning(&self) -> bool {
751754
match self.inner {
752-
DatabaseImpl::Sqlite(_) | DatabaseImpl::Postgres(_) => true,
755+
#[cfg(feature = "sqlite")]
756+
DatabaseImpl::Sqlite(_) => true,
757+
#[cfg(feature = "postgres")]
758+
DatabaseImpl::Postgres(_) => true,
759+
#[cfg(feature = "mysql")]
753760
DatabaseImpl::MySql(_) => false,
754761
}
755762
}
@@ -913,7 +920,7 @@ pub struct RowsNum(pub u64);
913920
/// ```
914921
/// use flareon::db::{model, Auto, Model};
915922
/// # use flareon::db::migrations::{Field, Operation};
916-
/// # use flareon::db::{Database, Identifier};
923+
/// # use flareon::db::{Database, Identifier, DatabaseField};
917924
/// # use flareon::Result;
918925
///
919926
/// #[model]
@@ -925,7 +932,7 @@ pub struct RowsNum(pub u64);
925932
/// # async fn main() -> Result<()> {
926933
///
927934
/// # const OPERATION: Operation = Operation::create_model()
928-
/// # .table_name(Identifier::new("todoapp__my_model"))
935+
/// # .table_name(Identifier::new("my_model"))
929936
/// # .fields(&[
930937
/// # Field::new(Identifier::new("id"), <i32 as DatabaseField>::TYPE)
931938
/// # .primary_key()
@@ -955,6 +962,7 @@ impl<T> Auto<T> {
955962
/// Creates a new `Auto` instance that is automatically generated by the
956963
/// database.
957964
#[must_use]
965+
#[allow(clippy::self_named_constructors)]
958966
pub const fn auto() -> Self {
959967
Self::Auto
960968
}
@@ -1025,6 +1033,8 @@ impl<const LIMIT: u32> PartialEq<LimitedString<LIMIT>> for String {
10251033
}
10261034
}
10271035

1036+
/// An error returned by [`LimitedString::new`] when the string is longer than
1037+
/// the specified limit.
10281038
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Error)]
10291039
#[error("string is too long ({length} > {LIMIT})")]
10301040
pub struct NewLimitedStringError<const LIMIT: u32> {

flareon/src/db/fields.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,23 @@ impl<T: DatabaseField> DatabaseField for Auto<T> {
288288
}
289289

290290
impl<T: DatabaseField> FromDbValue for Auto<T> {
291+
#[cfg(feature = "sqlite")]
291292
fn from_sqlite(value: SqliteValueRef) -> Result<Self>
292293
where
293294
Self: Sized,
294295
{
295296
Ok(Self::fixed(T::from_sqlite(value)?))
296297
}
297298

299+
#[cfg(feature = "postgres")]
298300
fn from_postgres(value: PostgresValueRef) -> Result<Self>
299301
where
300302
Self: Sized,
301303
{
302304
Ok(Self::fixed(T::from_postgres(value)?))
303305
}
304306

307+
#[cfg(feature = "mysql")]
305308
fn from_mysql(value: MySqlValueRef) -> Result<Self>
306309
where
307310
Self: Sized,
@@ -323,20 +326,23 @@ impl<T: DatabaseField> FromDbValue for Option<Auto<T>>
323326
where
324327
Option<T>: FromDbValue,
325328
{
329+
#[cfg(feature = "sqlite")]
326330
fn from_sqlite(value: SqliteValueRef) -> Result<Self>
327331
where
328332
Self: Sized,
329333
{
330334
<Option<T>>::from_sqlite(value).map(|value| value.map(Auto::fixed))
331335
}
332336

337+
#[cfg(feature = "postgres")]
333338
fn from_postgres(value: PostgresValueRef) -> Result<Self>
334339
where
335340
Self: Sized,
336341
{
337342
<Option<T>>::from_postgres(value).map(|value| value.map(Auto::fixed))
338343
}
339344

345+
#[cfg(feature = "mysql")]
340346
fn from_mysql(value: MySqlValueRef) -> Result<Self>
341347
where
342348
Self: Sized,

flareon/src/db/relations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl From<ForeignKeyOnDeletePolicy> for sea_query::ForeignKeyAction {
104104
}
105105
}
106106

107-
/// A foreign key on delete constraint.
107+
/// A foreign key on update constraint.
108108
///
109109
/// This is used to define the behavior of a foreign key when the referenced row
110110
/// is updated.

0 commit comments

Comments
 (0)