Pārlūkot izejas kodu

Began switching Database trait to Schema trait.

Kestrel 3 nedēļas atpakaļ
vecāks
revīzija
f616cebfb2

+ 4 - 4
microrm-macros/src/lib.rs

@@ -2,9 +2,9 @@
 
 use proc_macro::TokenStream;
 
-mod database;
 mod entity;
 mod index;
+mod schema;
 mod value;
 
 /// `Entity` trait derivation procedural macro.
@@ -70,9 +70,9 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
 /// - All fields of the given struct must derive the `DatabaseItem` trait.
 ///
 /// Refer to the `microrm` examples for example usage.
-#[proc_macro_derive(Database)]
-pub fn derive_database(tokens: TokenStream) -> TokenStream {
-    database::derive(tokens)
+#[proc_macro_derive(Schema)]
+pub fn derive_schema(tokens: TokenStream) -> TokenStream {
+    schema::derive(tokens)
 }
 
 /// Index columns specification macro.

+ 2 - 2
microrm-macros/src/database.rs → microrm-macros/src/schema.rs

@@ -36,7 +36,7 @@ pub fn derive(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
             .map(|f| (f.ident.unwrap(), f.ty))
             .collect::<Vec<_>>()
     } else {
-        panic!("Can only derive Database on data structs with named fields!");
+        panic!("Can only derive Schema on data structs with named fields!");
     };
 
     let db_ident = input.ident;
@@ -58,7 +58,7 @@ pub fn derive(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
     });
 
     quote! {
-        impl ::microrm::schema::Database for #db_ident {
+        impl ::microrm::schema::Schema for #db_ident {
             fn build() -> Self where Self: Sized {
                 Self { #(#build_method),* }
             }

+ 4 - 4
microrm/src/lib.rs

@@ -19,7 +19,7 @@
 //!
 //! microrm pushes the Rust type system somewhat to provide better ergonomics, so the MSRV is
 //! currently 1.75. Don't be scared off by the web of traits in the `schema` module --- you should
-//! never need to interact with any of them!
+//! never need to interact with most of them unless you're doing schema reflection.
 //!
 //! ### Examples
 //! #### KV-store
@@ -36,7 +36,7 @@
 //!     value: String,
 //! }
 //!
-//! #[derive(Database)]
+//! #[derive(Schema)]
 //! struct KVDB {
 //!     kvs: microrm::IDMap<KVEntry>,
 //! }
@@ -239,8 +239,8 @@ pub mod cli;
 /// Module prelude with commonly-used traits that shouldn't have overlap with other crates.
 pub mod prelude {
     pub use crate::query::{Insertable, Queryable, RelationInterface};
-    pub use crate::schema::{relation::Relation, Database, Serializable};
-    pub use microrm_macros::{Database, Entity, Value};
+    pub use crate::schema::{relation::Relation, Schema, Serializable};
+    pub use microrm_macros::{Entity, Schema, Value};
 }
 
 // ----------------------------------------------------------------------

+ 1 - 1
microrm/src/schema.rs

@@ -300,7 +300,7 @@ pub trait DatabaseItemVisitor {
 }
 
 /// A root structure for the database specification graph.
-pub trait Database {
+pub trait Schema {
     /*
     /// Open the SQLite database at the given URI and return it as an instance of a schema.
     ///

+ 3 - 2
microrm/src/schema/build.rs

@@ -1,6 +1,5 @@
 use crate::{
     db::ConnectionLease,
-    prelude::*,
     query::{Insertable, Queryable},
     schema::{
         collect::{EntityStateContainer, PartType},
@@ -10,6 +9,8 @@ use crate::{
     DBResult,
 };
 
+use super::Schema;
+
 #[derive(Debug)]
 struct ColumnInfo {
     name: &'static str,
@@ -146,7 +147,7 @@ impl DatabaseSchema {
     }
 }
 
-pub(crate) fn collect_from_database<DB: Database>() -> DatabaseSchema {
+pub(crate) fn collect_from_database<DB: Schema>() -> DatabaseSchema {
     struct IV(EntityStateContainer, Vec<IndexInfo>);
 
     impl DatabaseItemVisitor for IV {

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

@@ -9,7 +9,7 @@ pub struct MicrormMeta {
     pub value: String,
 }
 
-#[derive(microrm_macros::Database)]
+#[derive(microrm_macros::Schema)]
 pub struct MetadataDB {
     pub metastore: IDMap<MicrormMeta>,
 }

+ 1 - 1
microrm/tests/common/mod.rs

@@ -1,6 +1,6 @@
 use microrm::prelude::*;
 
-pub fn open_test_db_helper<DB: Database>(identifier: &'static str) -> DB {
+pub fn open_test_db_helper<DB: Schema>(identifier: &'static str) -> DB {
     let path = format!(
         "{tmpdir}/{identifier}.db",
         tmpdir = std::env!("CARGO_TARGET_TMPDIR"),

+ 1 - 1
microrm/tests/derive.rs

@@ -1,7 +1,7 @@
 #![allow(unused)]
 
 use microrm::prelude::*;
-use microrm::schema::{Database, IDMap};
+use microrm::schema::SchemaIDMap;
 use test_log::test;
 
 mod common;

+ 2 - 2
microrm/tests/manual_construction.rs

@@ -4,7 +4,7 @@
 use microrm::db::{ConnectionPool, StatementContext, StatementRow};
 use microrm::schema::datum::{ConcreteDatum, Datum};
 use microrm::schema::entity::{Entity, EntityID, EntityPart, EntityPartVisitor, EntityVisitor};
-use microrm::schema::{Database, DatabaseItem, DatabaseItemVisitor, IDMap};
+use microrm::schema::{DatabaseItemVisitor, IDMap, SchemaDatabaseItem};
 use test_log::test;
 
 #[derive(Debug)]
@@ -124,7 +124,7 @@ struct SimpleDatabase {
     strings: IDMap<SimpleEntity>,
 }
 
-impl Database for SimpleDatabase {
+impl Schema for SimpleDatabase {
     fn build() -> Self
     where
         Self: Sized,