Преглед на файлове

Rename migration to migrate, fix several clippy nits.

Kestrel преди 2 седмици
родител
ревизия
c867cff475

+ 1 - 22
microrm-macros/src/schema.rs

@@ -1,25 +1,4 @@
-use quote::{quote, ToTokens};
-
-fn type_to_expression_context_type(ty: &syn::Type) -> proc_macro2::TokenStream {
-    fn handle_path_segment(seg: &syn::PathSegment) -> proc_macro2::TokenStream {
-        let ident = &seg.ident;
-        let args = &seg.arguments;
-        match seg.arguments.is_empty() {
-            true => quote! { #ident },
-            false => quote! { #ident :: #args },
-        }
-    }
-
-    match ty {
-        syn::Type::Path(path) => {
-            let new_segments = path.path.segments.iter().map(handle_path_segment);
-            quote! {
-                #(#new_segments)::*
-            }
-        },
-        v => v.into_token_stream(),
-    }
-}
+use quote::quote;
 
 pub fn derive(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
     let input: syn::DeriveInput = syn::parse_macro_input!(tokens);

+ 1 - 1
microrm/Cargo.toml

@@ -16,7 +16,7 @@ all-features = true
 [features]
 clap = ["dep:clap"]
 bundled_sqlite = ["libsqlite3-sys/bundled"]
-unstable_migration = []
+migrate = []
 
 [dependencies]
 libsqlite3-sys = "0.28"

+ 2 - 1
microrm/src/query.rs

@@ -62,8 +62,9 @@ pub(crate) enum QueryPart {
     Trailing,
 }
 
+/// Represents a SQL query built during runtime.
 #[derive(Debug)]
-pub(crate) struct Query<'l> {
+pub struct Query<'l> {
     parts: HashMap<QueryPart, Vec<QueryPartData<'l>>>,
 }
 

+ 2 - 2
microrm/src/schema.rs

@@ -28,8 +28,8 @@ pub mod relation;
 /// Types related to indexes.
 pub mod index;
 
-#[cfg(feature = "unstable_migration")]
-pub mod migration;
+#[cfg(feature = "migrate")]
+pub mod migrate;
 
 mod build;
 mod collect;

+ 11 - 7
microrm/src/schema/build.rs

@@ -106,15 +106,19 @@ pub(crate) struct DatabaseSchema {
 impl DatabaseSchema {
     pub(crate) const SCHEMA_SIGNATURE_KEY: &'static str = "schema_signature";
 
-    pub fn signature(&self) -> &str {
+    // the following functions are for use in migrations
+    #[allow(unused)]
+    pub(crate) fn signature(&self) -> &str {
         self.signature.as_str()
     }
 
-    pub fn table_queries(&self) -> &HashMap<String, String> {
+    #[allow(unused)]
+    pub(crate) fn table_queries(&self) -> &HashMap<String, String> {
         &self.table_queries
     }
 
-    pub fn index_queries(&self) -> &HashMap<String, String> {
+    #[allow(unused)]
+    pub(crate) fn index_queries(&self) -> &HashMap<String, String> {
         &self.index_queries
     }
 
@@ -163,7 +167,7 @@ impl DatabaseSchema {
             txn.lease(),
             meta::MicrormMeta {
                 key: Self::SCHEMA_SIGNATURE_KEY.into(),
-                value: format!("{}", self.signature),
+                value: self.signature.clone(),
             },
         )?;
 
@@ -334,8 +338,8 @@ pub(crate) fn collect_from_database<DB: Schema>(schema: &DB) -> DatabaseSchema {
     let digest = hasher.finalize();
 
     DatabaseSchema {
-        signature: digest.into_iter().map(|v| format!("{:02x}", v)).collect(),
-        table_queries: HashMap::from_iter(table_queries.into_iter()),
-        index_queries: HashMap::from_iter(index_queries.into_iter()),
+        signature: digest.into_iter().fold(String::new(), |mut a, v| { a += &format!("{:02x}", v); a }),
+        table_queries: HashMap::from_iter(table_queries),
+        index_queries: HashMap::from_iter(index_queries),
     }
 }

+ 1 - 1
microrm/src/schema/datum.rs

@@ -121,7 +121,7 @@ pub trait DatumList: Clone {
     /// Create a copy of the tail of this list.
     fn list_tail(&self) -> Self::ListTail;
     /// Create a referenced version of the current list; see [`Self::RefList`].
-    fn into_ref<'l>(&'l self) -> Self::RefList<'l> {
+    fn create_ref(&self) -> Self::RefList<'_> {
         todo!()
     }
 

+ 4 - 10
microrm/src/schema/datum/datum_list.rs

@@ -14,9 +14,7 @@ impl DatumList for () {
     fn list_head(&self) -> &Self::ListHead {
         unreachable!()
     }
-    fn list_tail(&self) -> Self::ListTail {
-        ()
-    }
+    fn list_tail(&self) -> Self::ListTail { }
 
     fn accept(&self, _: &mut impl DatumVisitor) {}
 }
@@ -38,9 +36,7 @@ impl<T: Datum> DatumList for T {
     fn list_head(&self) -> &Self::ListHead {
         self
     }
-    fn list_tail(&self) -> Self::ListTail {
-        ()
-    }
+    fn list_tail(&self) -> Self::ListTail { }
 
     fn accept(&self, visitor: &mut impl DatumVisitor) {
         visitor.visit(self);
@@ -65,9 +61,7 @@ impl<T0: Datum> DatumList for (T0,) {
     fn list_head(&self) -> &Self::ListHead {
         &self.0
     }
-    fn list_tail(&self) -> Self::ListTail {
-        ()
-    }
+    fn list_tail(&self) -> Self::ListTail { }
 
     fn accept(&self, visitor: &mut impl DatumVisitor) {
         visitor.visit(&self.0);
@@ -106,9 +100,9 @@ macro_rules! datum_list {
 
         impl<$ty0: ConcreteDatum, $( $ty: ConcreteDatum ),*> ConcreteDatumList for ($ty0, $($ty),*) {
             fn build_equivalent<'l>(mut from: impl Iterator<Item = &'l str>) -> Option<impl QueryEquivalentList<Self> + 'l> {
+                #[allow(clippy::eq_op)]
                 Some((
                     StringQuery( from.next()? ),
-                #[allow(clippy::eq_op)]
                     $( if $n == $n { StringQuery( from.next()? ) } else { panic!() } ),*
                 ))
             }

+ 0 - 0
microrm/src/schema/migration.rs → microrm/src/schema/migrate.rs


+ 0 - 0
microrm/src/schema/migration/new.rs → microrm/src/schema/migrate/new.rs


+ 0 - 0
microrm/src/schema/tests.rs


+ 2 - 2
microrm/tests/migration.rs

@@ -1,8 +1,8 @@
-#![cfg(feature = "unstable_migration")]
+#![cfg(feature = "migrate")]
 
 use microrm::{
     prelude::*,
-    schema::migration::{Migration, Migrator},
+    schema::migrate::{Migration, Migrator},
     ConnectionPool,
 };
 use test_log::test;