Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove butane_type for FieldType derived enums #99

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions butane/tests/custom_enum_derived.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Tests deriving FieldType for an enum
use butane::db::Connection;
use butane::prelude::*;
use butane::{butane_type, model, query};
use butane::{model, query};
use butane::{FieldType, FromSql, ObjectState, SqlVal, ToSql};

use butane_test_helper::*;

#[butane_type(Text)]
#[derive(PartialEq, Eq, Debug, Clone, FieldType)]
enum Whatsit {
Foo,
Expand Down
15 changes: 11 additions & 4 deletions butane_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

extern crate proc_macro;

use butane_core::{codegen, make_compile_error, migrations};
use butane_core::migrations::adb::{DeferredSqlType, TypeIdentifier};
use butane_core::{codegen, make_compile_error,SqlType, migrations};
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use proc_macro2::TokenTree;
Expand Down Expand Up @@ -189,6 +190,15 @@ fn derive_field_type_for_enum(ident: &Ident, data_enum: syn::DataEnum) -> TokenS
return derive_field_type_with_json(ident);
}

let mut migrations = migrations_for_dir();

codegen::add_custom_type(
&mut migrations,
ident.to_string(),
DeferredSqlType::KnownId(TypeIdentifier::Ty(SqlType::Text)),
)
.unwrap();

let match_arms_to_string: Vec<TokenStream2> = data_enum
.variants
.iter()
Expand Down Expand Up @@ -254,9 +264,6 @@ fn derive_field_type_for_enum(ident: &Ident, data_enum: syn::DataEnum) -> TokenS

#[cfg(feature = "json")]
fn derive_field_type_with_json(struct_name: &Ident) -> TokenStream {
use butane_core::migrations::adb::{DeferredSqlType, TypeIdentifier};
use butane_core::SqlType;

let mut migrations = migrations_for_dir();

codegen::add_custom_type(
Expand Down