fn build_select(&self, query: &Select, build_mode: &BuildMode) -> SqlFrag {
        let use_complete_name = query.joins.is_empty();
        let mut w = SqlFrag::new(self.sql_options(), build_mode);
        w.left_river("SELECT");
        self.build_enumerated_fields(&mut w, use_complete_name, &query.enumerated_fields); //TODO: add support for column_sql, fields, functions
        w.left_river("FROM");

        assert!(!query.from.is_empty(),
                "There should be table, query, function to select from");
        let mut do_comma = false;
        for field in &query.from {
            if do_comma {
                w.commasp();
            } else {
                do_comma = true;
            }
            self.build_source_field(&mut w, field);
        }
        if !query.joins.is_empty() {
            for join in &query.joins {
                match join.modifier {
                    Some(ref modifier) => {
                        match *modifier {
                            Modifier::LEFT => w.right_river("LEFT "),
                            Modifier::RIGHT => w.right_river("RIGHT "),
                            Modifier::FULL => w.right_river("FULL "),
                        };
                    }
                    None => (),
                }
                match join.join_type {
                    Some(ref join_type) => {
                        match *join_type {
                            JoinType::CROSS => w.right_river("CROSS "),
                            JoinType::INNER => w.right_river("INNER "),
                            JoinType::OUTER => w.right_river("OUTER "),
                            JoinType::NATURAL => w.right_river("NATURAL "),
                        };
                    }
                    None => (),
                }
                w.append("JOIN ");
                w.append(&join.table_name.complete_name());
                w.right_river("ON ");
                self.build_filter(&mut w, use_complete_name, &join.on);
            }
        }

        if !query.filters.is_empty() {
            w.left_river("WHERE ");
            self.build_filters(&mut w, use_complete_name, &query.filters);
        }

        if !query.group_by.is_empty() {
            w.left_river("GROUP BY ");
            let mut do_comma = false;
            for operand in &query.group_by {
                if do_comma {
                    w.comma();
                } else {
                    do_comma = true;
                }
                self.build_operand(&mut w, use_complete_name, operand);
                w.append(" ");
            }
        }

        if !query.having.is_empty() {
            w.left_river("HAVING ");
            let mut do_comma = false;
            for hav in &query.having {
                if do_comma {
                    w.commasp();
                } else {
                    do_comma = true;
                }
                self.build_filter(&mut w, use_complete_name, hav);
            }
        }

        if !query.order_by.is_empty() {
            w.left_river("ORDER BY ");
            let mut do_comma = false;
            for order in &query.order_by {
                if do_comma {
                    w.commasp();
                } else {
                    do_comma = true;
                }
                self.build_operand(&mut w, use_complete_name, &order.operand);
                match &order.direction {
                    &Some(ref direction) => {
                        match direction {
                            &Direction::ASC => w.append(" ASC"),
                            &Direction::DESC => w.append(" DESC"),
                        }
                    }
                    &None => w.append(""),
                };
                match &order.nulls_where {
                    &Some(ref nulls_where) => {
                        match nulls_where {
                            &NullsWhere::FIRST => w.append(" NULLS FIRST"),
                            &NullsWhere::LAST => w.append(" NULLS LAST"),
                        }
                    }
                    &None => w.append(""),
                };
            }
        }
        match query.range.limit {
            Some(limit) => {
                w.left_river("LIMIT ");
                w.append(&format!("{}", limit));
            }
            None => (),
        }
        match query.range.offset {
            Some(offset) => {
                w.left_river("OFFSET ");
                w.append(&format!("{}", offset));
            }
            None => (),
        }
        w
    }
/// build the select statment from the query object
build the select statment from the query object
build the select statment from the query object
fn build_select(&self, query: &Select, build_mode: &BuildMode) -> SqlFrag {
        let use_complete_name = query.joins.is_empty();
        let mut w = SqlFrag::new(self.sql_options(), build_mode);
        w.left_river("SELECT");
        self.build_enumerated_fields(&mut w, use_complete_name, &query.enumerated_fields); //TODO: add support for column_sql, fields, functions
        w.left_river("FROM");
        assert!(!query.from.is_empty(),
                "There should be table, query, function to select from");
        let mut do_comma = false;
        for field in &query.from {
            if do_comma {
                w.commasp();
            } else {
                do_comma = true;
            }
            self.build_source_field(&mut w, field);
        }
        if !query.joins.is_empty() {
            for join in &query.joins {
                match join.modifier {
                    Some(ref modifier) => {
                        match *modifier {
                            Modifier::LEFT => w.right_river("LEFT "),
                            Modifier::RIGHT => w.right_river("RIGHT "),
                            Modifier::FULL => w.right_river("FULL "),
                        };
                    }
                    None => (),
                }
                match join.join_type {
                    Some(ref join_type) => {
                        match *join_type {
                            JoinType::CROSS => w.right_river("CROSS "),
                            JoinType::INNER => w.right_river("INNER "),
                            JoinType::OUTER => w.right_river("OUTER "),
                            JoinType::NATURAL => w.right_river("NATURAL "),
                        };
                    }
                    None => (),
                }
                w.append("JOIN ");
                w.append(&join.table_name.complete_name());
                w.right_river("ON ");
                self.build_filter(&mut w, use_complete_name, &join.on);
            }
        }
        if !query.filters.is_empty() {
            w.left_river("WHERE ");
            self.build_filters(&mut w, use_complete_name, &query.filters);
        }
        if !query.group_by.is_empty() {
            w.left_river("GROUP BY ");
            let mut do_comma = false;
            for operand in &query.group_by {
                if do_comma {
                    w.comma();
                } else {
                    do_comma = true;
                }
                self.build_operand(&mut w, use_complete_name, operand);
                w.append(" ");
            }
        }
        if !query.having.is_empty() {
            w.left_river("HAVING ");
            let mut do_comma = false;
            for hav in &query.having {
                if do_comma {
                    w.commasp();
                } else {
                    do_comma = true;
                }
                self.build_filter(&mut w, use_complete_name, hav);
            }
        }
        if !query.order_by.is_empty() {
            w.left_river("ORDER BY ");
            let mut do_comma = false;
            for order in &query.order_by {
                if do_comma {
                    w.commasp();
                } else {
                    do_comma = true;
                }
                self.build_operand(&mut w, use_complete_name, &order.operand);
                match &order.direction {
                    &Some(ref direction) => {
                        match direction {
                            &Direction::ASC => w.append(" ASC"),
                            &Direction::DESC => w.append(" DESC"),
                        }
                    }
                    &None => w.append(""),
                };
                match &order.nulls_where {
                    &Some(ref nulls_where) => {
                        match nulls_where {
                            &NullsWhere::FIRST => w.append(" NULLS FIRST"),
                            &NullsWhere::LAST => w.append(" NULLS LAST"),
                        }
                    }
                    &None => w.append(""),
                };
            }
        }
        match query.range.limit {
            Some(limit) => {
                w.left_river("LIMIT ");
                w.append(&format!("{}", limit));
            }
            None => (),
        }
        match query.range.offset {
            Some(offset) => {
                w.left_river("OFFSET ");
                w.append(&format!("{}", offset));
            }
            None => (),
        }
        w
    }
fn build_select ( & self , query : & Select , build_mode : & BuildMode ) -> SqlFrag { let use_complete_name = query . joins . is_empty ( ) ; let mut w = SqlFrag :: new ( self . sql_options ( ) , build_mode ) ; w . left_river ( " " ) ; self . build_enumerated_fields ( & mut w , use_complete_name , & query . enumerated_fields ) ; //TODO: add support for column_sql, fields, functions w . left_river ( " " ) ; assert ! ( query from is_empty ( ) " " ) ; let mut do_comma = false ; for field in & query . from { if do_comma { w . commasp ( ) ; } else { do_comma = true ; } self . build_source_field ( & mut w , field ) ; } if ! query . joins . is_empty ( ) { for join in & query . joins { match join . modifier { Some ( ref modifier ) => { match * modifier { Modifier :: LEFT => w . right_river ( " " ) , Modifier :: RIGHT => w . right_river ( " " ) , Modifier :: FULL => w . right_river ( " " ) , } ; } None => ( ) , } match join . join_type { Some ( ref join_type ) => { match * join_type { JoinType :: CROSS => w . right_river ( " " ) , JoinType :: INNER => w . right_river ( " " ) , JoinType :: OUTER => w . right_river ( " " ) , JoinType :: NATURAL => w . right_river ( " " ) , } ; } None => ( ) , } w . append ( " " ) ; w . append ( & join . table_name . complete_name ( ) ) ; w . right_river ( " " ) ; self . build_filter ( & mut w , use_complete_name , & join . on ) ; } } if ! query . filters . is_empty ( ) { w . left_river ( " " ) ; self . build_filters ( & mut w , use_complete_name , & query . filters ) ; } if ! query . group_by . is_empty ( ) { w . left_river ( " " ) ; let mut do_comma = false ; for operand in & query . group_by { if do_comma { w . comma ( ) ; } else { do_comma = true ; } self . build_operand ( & mut w , use_complete_name , operand ) ; w . append ( " " ) ; } } if ! query . having . is_empty ( ) { w . left_river ( " " ) ; let mut do_comma = false ; for hav in & query . having { if do_comma { w . commasp ( ) ; } else { do_comma = true ; } self . build_filter ( & mut w , use_complete_name , hav ) ; } } if ! query . order_by . is_empty ( ) { w . left_river ( " " ) ; let mut do_comma = false ; for order in & query . order_by { if do_comma { w . commasp ( ) ; } else { do_comma = true ; } self . build_operand ( & mut w , use_complete_name , & order . operand ) ; match & order . direction { & Some ( ref direction ) => { match direction { & Direction :: ASC => w . append ( " " ) , & Direction :: DESC => w . append ( " " ) , } } & None => w . append ( " " ) , } ; match & order . nulls_where { & Some ( ref nulls_where ) => { match nulls_where { & NullsWhere :: FIRST => w . append ( " " ) , & NullsWhere :: LAST => w . append ( " " ) , } } & None => w . append ( " " ) , } ; } } match query . range . limit { Some ( limit ) => { w . left_river ( " " ) ; w . append ( & format ! ( " " limit ) ) ; } None => ( ) , } match query . range . offset { Some ( offset ) => { w . left_river ( " " ) ; w . append ( & format ! ( " " offset ) ) ; } None => ( ) , } w }
build the select statment from the query object
build the select statment from the query object
&self
query
&Select
build_mode
&BuildMode
&self
query
&Select
build_mode
&BuildMode