Generator

Trait Generator 

Source
pub trait Generator {
Show 16 methods // Required methods fn query_columns( &self, conn_url: &str, table_name: &str, ) -> impl Future<Output = Vec<ColumnInfo>> + Send; fn get_mapping_type(&self, sql_type: &str) -> String; // Provided methods fn gen_file( &self, conn_url: &str, table_name: &str, ) -> impl Future<Output = Result<(), Error>> + Send where Self: Sync { ... } fn gen_struct( &self, table_name: &str, column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_struct_name(&self, table: &str) -> String { ... } fn gen_field_and_value_str( &self, column_infos: &Vec<ColumnInfo>, contain_id: bool, ) -> String { ... } fn gen_field_and_batch_values_str( &self, column_infos: &Vec<ColumnInfo>, contain_id: bool, ) -> String { ... } fn gen_insert_returning_id_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_insert_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_batch_insert_returning_id_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_batch_insert_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_select_sql( &self, table_name: &str, column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_select_sql_fn( &self, table_name: &str, column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_select_by_id_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String { ... } fn gen_delete_by_id_sql(&self, table_name: &str) -> String { ... } fn gen_delete_by_id_fn(&self, _table_name: &str) -> String { ... }
}

Required Methods§

Source

fn query_columns( &self, conn_url: &str, table_name: &str, ) -> impl Future<Output = Vec<ColumnInfo>> + Send

Source

fn get_mapping_type(&self, sql_type: &str) -> String

Provided Methods§

Source

fn gen_file( &self, conn_url: &str, table_name: &str, ) -> impl Future<Output = Result<(), Error>> + Send
where Self: Sync,

This is a tool for gen table_name mapping Struct and basic sql, such as insert.

Based on sqlx and sql_builder

generate a {table_name}.rs for one table

now support

! MySql

! postgres

include: a table name struct with field.

insert function

insert_returning_id function

batch_insert function

batch_insert_returning_id function

§Examples
use sql_wrapper::generator::Generator;
use sql_wrapper::pg_generator;
    let gen = pg_generator::PgGenerator{};
    let conn_url = "postgres://postgres:123456@localhost/jixin_message?&stringtype=unspecified";
    let table_name = "test_table";
    let result = gen.gen_file(conn_url, table_name).await;
    println!("result:{:?}", result)

after run , if success, test_table.rs file would generate.

Examples found in repository?
examples/pg_examples.rs (line 10)
5async fn main() {
6    // it will generate a file table_name.rs whit table struct, get 4 insert functions
7    let gen = pg_generator::PgGenerator{};
8    let conn_url = "postgres://postgres:123456@localhost/jixin_message?&stringtype=unspecified";
9    let table_name = "test_table";
10    let result = gen.gen_file(conn_url, table_name).await;
11    println!("result:{:?}", result)
12}
Source

fn gen_struct(&self, table_name: &str, column_infos: &Vec<ColumnInfo>) -> String

Source

fn gen_struct_name(&self, table: &str) -> String

Source

fn gen_field_and_value_str( &self, column_infos: &Vec<ColumnInfo>, contain_id: bool, ) -> String

Source

fn gen_field_and_batch_values_str( &self, column_infos: &Vec<ColumnInfo>, contain_id: bool, ) -> String

Source

fn gen_insert_returning_id_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String

Source

fn gen_insert_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String

Source

fn gen_batch_insert_returning_id_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String

Source

fn gen_batch_insert_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String

Source

fn gen_select_sql( &self, table_name: &str, column_infos: &Vec<ColumnInfo>, ) -> String

Source

fn gen_select_sql_fn( &self, table_name: &str, column_infos: &Vec<ColumnInfo>, ) -> String

Source

fn gen_select_by_id_fn( &self, _table_name: &str, _column_infos: &Vec<ColumnInfo>, ) -> String

Source

fn gen_delete_by_id_sql(&self, table_name: &str) -> String

Source

fn gen_delete_by_id_fn(&self, _table_name: &str) -> String

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§