@@ -57,6 +57,38 @@ impl StringType {
5757 }
5858}
5959
60+ /// Available options for bytes types
61+ #[ derive( Debug , Clone , Copy , PartialEq , Default ) ]
62+ pub enum BytesType {
63+ /// Use `Vec<u8>`
64+ #[ default]
65+ Vec ,
66+ /// Use `&[u8]`
67+ Slice ,
68+ /// Use `Cow<[u8]>`
69+ Cow ,
70+ }
71+
72+ impl BytesType {
73+ /// Get the current [BytesType] as a rust type string
74+ pub fn as_str ( & self ) -> & ' static str {
75+ match self {
76+ BytesType :: Vec => "Vec<u8>" ,
77+ BytesType :: Slice => "&'a [u8]" ,
78+ BytesType :: Cow => "Cow<'a, [u8]>" ,
79+ }
80+ }
81+
82+ /// Get the lifetime used for the current [BytesType]
83+ pub fn get_lifetime ( & self ) -> & ' static str {
84+ match self {
85+ BytesType :: Vec => "" ,
86+ BytesType :: Slice => "'a" ,
87+ BytesType :: Cow => "'a" ,
88+ }
89+ }
90+ }
91+
6092/// Options for a individual table
6193#[ derive( Debug , Clone ) ]
6294pub struct TableOptions < ' a > {
@@ -85,6 +117,12 @@ pub struct TableOptions<'a> {
85117 /// Determines which string type to use for Update* structs
86118 update_str_type : StringType ,
87119
120+ /// Determines which bytes type to use for Create* structs
121+ create_bytes_type : BytesType ,
122+
123+ /// Determines which bytes type to use for Update* structs
124+ update_bytes_type : BytesType ,
125+
88126 /// Only Generate a single model file instead of a directory with "mod.rs" and "generated.rs"
89127 single_model_file : bool ,
90128
@@ -123,6 +161,14 @@ impl<'a> TableOptions<'a> {
123161 self . update_str_type
124162 }
125163
164+ pub fn get_create_bytes_type ( & self ) -> BytesType {
165+ self . create_bytes_type
166+ }
167+
168+ pub fn get_update_bytes_type ( & self ) -> BytesType {
169+ self . update_bytes_type
170+ }
171+
126172 pub fn get_autogenerated_columns ( & self ) -> & [ & ' _ str ] {
127173 self . autogenerated_columns . as_deref ( ) . unwrap_or_default ( )
128174 }
@@ -193,6 +239,20 @@ impl<'a> TableOptions<'a> {
193239 }
194240 }
195241
242+ pub fn create_bytes_type ( self , type_ : BytesType ) -> Self {
243+ Self {
244+ create_bytes_type : type_,
245+ ..self
246+ }
247+ }
248+
249+ pub fn update_bytes_type ( self , type_ : BytesType ) -> Self {
250+ Self {
251+ update_bytes_type : type_,
252+ ..self
253+ }
254+ }
255+
196256 pub fn set_read_only ( & mut self , value : bool ) {
197257 self . read_only = value;
198258 }
@@ -214,6 +274,8 @@ impl<'a> TableOptions<'a> {
214274 fns : self . fns || other. fns ,
215275 create_str_type : other. create_str_type ,
216276 update_str_type : other. update_str_type ,
277+ create_bytes_type : other. create_bytes_type ,
278+ update_bytes_type : other. update_bytes_type ,
217279 single_model_file : self . single_model_file || other. single_model_file ,
218280 read_only : self . read_only || other. read_only ,
219281 }
@@ -233,6 +295,8 @@ impl<'a> Default for TableOptions<'a> {
233295 fns : true ,
234296 create_str_type : Default :: default ( ) ,
235297 update_str_type : Default :: default ( ) ,
298+ create_bytes_type : Default :: default ( ) ,
299+ update_bytes_type : Default :: default ( ) ,
236300 single_model_file : false ,
237301 read_only : false ,
238302 }
0 commit comments