Skip to content

Commit a04619c

Browse files
author
jcesar
committed
releasing 0.0.2 on crates.io
1 parent 2fa23a0 commit a04619c

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

examples/generate_model_code.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn main(){
1717
use_condensed_name:true,
1818
generate_table_meta:true,
1919
base_dir:"./examples".to_string(),
20+
include_views: true,
2021
};
2122
generator::generate_all(db.as_dev(), &config);
2223
}

src/generator.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub struct Config{
2525

2626
/// base directory for the generated content
2727
pub base_dir: String,
28+
29+
/// whether to include generating views
30+
pub include_views: bool,
2831
}
2932

3033
impl Config{
@@ -36,6 +39,7 @@ impl Config{
3639
use_condensed_name:true,
3740
generate_table_meta:true,
3841
base_dir:"./src".to_string(),
42+
include_views: true,
3943
}
4044
}
4145

@@ -75,9 +79,9 @@ impl Config{
7579
pub fn get_all_tables(db_dev:&DatabaseDev)->Vec<Table>{
7680
let all_tables_names = db_dev.get_all_tables();
7781
let mut all_table_def:Vec<Table> = Vec::new();
78-
for (schema, table) in all_tables_names{
82+
for (schema, table, is_view) in all_tables_names{
7983
println!("Extracted {}.{}", schema,table);
80-
let meta = db_dev.get_table_metadata(&schema, &table);
84+
let meta = db_dev.get_table_metadata(&schema, &table, is_view);
8185
all_table_def.push(meta);
8286
}
8387
all_table_def
@@ -136,6 +140,7 @@ pub fn generate_tables(db_dev:&DatabaseDev, only_tables:Vec<String>, config:&Con
136140
generate_mod_rs(&config, &tables);
137141
generate_mod_table_names(&config, &tables);
138142
generate_mod_column_names(&config, &tables);
143+
generate_mod_schema_names(&config, &tables);
139144
}
140145

141146
/// the gernaration of tables should be placed on their respective directory
@@ -210,6 +215,19 @@ fn generate_mod_per_schema(config:&Config, all_tables:&Vec<Table>){
210215
}
211216
}
212217

218+
/// listing down schemas in the database
219+
fn generate_mod_schema_names(config:&Config, all_tables:&Vec<Table>){
220+
let schemas = get_schemas(all_tables);
221+
let mut w = Writer::new();
222+
for schema in schemas{
223+
w.ln();
224+
w.appendln("#[allow(non_upper_case_globals)]");
225+
w.appendln(&format!("pub const {}: &'static str = \"{}\";",schema, schema));
226+
}
227+
let module_dir = config.module_base_dir();
228+
let mod_file = format!("{}/schema.rs", module_dir);
229+
save_to_file(&mod_file, &w.src);
230+
}
213231
/// listing of all table names in the system
214232
fn generate_mod_table_names(config:&Config, all_tables:&Vec<Table>){
215233
let mut unique_table = vec![];
@@ -261,8 +279,11 @@ fn generate_mod_rs(config:&Config, all_tables:&Vec<Table>){
261279
w.append(schema);
262280
w.appendln(";");
263281
}
282+
w.ln();
283+
w.appendln("pub mod schema;");
264284
w.appendln("pub mod table;");
265285
w.appendln("pub mod column;");
286+
w.ln();
266287
w.appendln("use rustorm::table::Table;");
267288
w.appendln("use rustorm::table::IsTable;");
268289
for table in all_tables{

src/meta.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ impl MetaCode for Table{
171171
w.tabs(3);
172172
w.append("],");
173173
w.ln();
174+
w.tabs(3);
175+
w.append(&format!("is_view: {}",self.is_view));
176+
w.ln();
174177
w.tabs(2);
175178
w.append("}");
176179
imports.sort_by(|a, b| a.cmp(&b));
@@ -214,8 +217,7 @@ impl StructCode for Table{
214217
if self.comment.is_some(){
215218
w.append("///");
216219
w.ln();
217-
w.append("/// ");
218-
w.append(&self.comment.clone().unwrap());
220+
w.doc_comment(&self.comment.clone().unwrap());
219221
w.ln();
220222
w.append("///");
221223
w.ln();

src/writer.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ impl Writer{
6565
#[inline]
6666
pub fn comment(&mut self, comment: &str)->&mut Self{
6767
self.append("//");
68-
self.append(comment)
68+
self.append(comment);
69+
self
6970
}
7071

7172
#[inline]
73+
/// TODO: make escaping more formal
7274
pub fn doc_comment(&mut self, comment: &str)->&mut Self{
73-
self.append("///");
74-
self.append(comment)
75+
let splinters:Vec<&str> = comment.split('\n').collect();
76+
for sp in splinters{
77+
self.append("/// ");
78+
self.appendln(sp);
79+
}
80+
self
7581
}
7682

7783
#[inline]

0 commit comments

Comments
 (0)