@@ -81,15 +81,13 @@ impl Table {
8181 if col. is_pk {
8282 primary_key = col_name. to_string ( ) ;
8383 }
84- table_cols. push (
85- Column :: new (
86- col_name. to_string ( ) ,
87- col. datatype . to_string ( ) ,
88- col. is_pk ,
89- col. not_null ,
90- col. is_unique ,
91- ) ,
92- ) ;
84+ table_cols. push ( Column :: new (
85+ col_name. to_string ( ) ,
86+ col. datatype . to_string ( ) ,
87+ col. is_pk ,
88+ col. not_null ,
89+ col. is_unique ,
90+ ) ) ;
9391
9492 match DataType :: new ( col. datatype . to_string ( ) ) {
9593 DataType :: Integer => table_rows
@@ -139,27 +137,29 @@ impl Table {
139137 /// column with the specified key as a column name.
140138 ///
141139 pub fn get_column ( & mut self , column_name : String ) -> Result < & Column > {
142- if let Some ( column) = self . columns
140+ if let Some ( column) = self
141+ . columns
143142 . iter ( )
144143 . filter ( |c| c. column_name == column_name)
145144 . collect :: < Vec < & Column > > ( )
146- . first ( ) {
147- Ok ( column)
148- } else {
149- Err ( SQLRiteError :: General ( String :: from ( "Column not found." ) ) )
150- }
145+ . first ( )
146+ {
147+ Ok ( column)
148+ } else {
149+ Err ( SQLRiteError :: General ( String :: from ( "Column not found." ) ) )
150+ }
151151 }
152152
153153 /// Returns an mutable reference of `sql::db::table::Column` if the table contains a
154154 /// column with the specified key as a column name.
155155 ///
156156 pub fn get_column_mut < ' a > ( & mut self , column_name : String ) -> Result < & mut Column > {
157- for elem in self . columns . iter_mut ( ) {
158- if elem. column_name == column_name{
159- return Ok ( elem)
160- }
157+ for elem in self . columns . iter_mut ( ) {
158+ if elem. column_name == column_name {
159+ return Ok ( elem) ;
161160 }
162- Err ( SQLRiteError :: General ( String :: from ( "Column not found." ) ) )
161+ }
162+ Err ( SQLRiteError :: General ( String :: from ( "Column not found." ) ) )
163163 }
164164
165165 /// Validates if columns and values being inserted violate the UNIQUE constraint
@@ -224,7 +224,7 @@ impl Table {
224224 let mut next_rowid = self . last_rowid + i64:: from ( 1 ) ;
225225
226226 // Checks if table has a PRIMARY KEY
227- if self . primary_key != "-1" {
227+ if self . primary_key != "-1" {
228228 // Checking if primary key is in INSERT QUERY columns
229229 // If it is not, assign the next_rowid to it
230230 if !cols. iter ( ) . any ( |col| col == & self . primary_key ) {
@@ -288,21 +288,21 @@ impl Table {
288288 // For every column in the INSERT statement
289289 for i in 0 ..column_names. len ( ) {
290290 let mut val = String :: from ( "Null" ) ;
291- let mut key = & column_names[ i] ;
291+ let key = & column_names[ i] ;
292292
293- if let Some ( key) = & cols. get ( j) {
293+ if let Some ( key) = & cols. get ( j) {
294294 if & key. to_string ( ) == & column_names[ i] {
295295 // Getting column name
296296 val = values[ j] . to_string ( ) ;
297297 j += 1 ;
298- } else {
299- if & self . primary_key == & column_names[ i] {
300- continue
298+ } else {
299+ if & self . primary_key == & column_names[ i] {
300+ continue ;
301301 }
302302 }
303- } else {
304- if & self . primary_key == & column_names[ i] {
305- continue
303+ } else {
304+ if & self . primary_key == & column_names[ i] {
305+ continue ;
306306 }
307307 }
308308
@@ -367,10 +367,22 @@ impl Table {
367367 ///
368368 pub fn print_table_schema ( & self ) -> Result < usize > {
369369 let mut table = PrintTable :: new ( ) ;
370- table. add_row ( row ! [ "Column Name" , "Data Type" , "PRIMARY KEY" , "UNIQUE" , "NOT NULL" ] ) ;
370+ table. add_row ( row ! [
371+ "Column Name" ,
372+ "Data Type" ,
373+ "PRIMARY KEY" ,
374+ "UNIQUE" ,
375+ "NOT NULL"
376+ ] ) ;
371377
372378 for col in & self . columns {
373- table. add_row ( row ! [ col. column_name, col. datatype, col. is_pk, col. is_unique, col. not_null] ) ;
379+ table. add_row ( row ! [
380+ col. column_name,
381+ col. datatype,
382+ col. is_pk,
383+ col. is_unique,
384+ col. not_null
385+ ] ) ;
374386 }
375387
376388 let lines = table. printstd ( ) ;
@@ -415,7 +427,9 @@ impl Table {
415427
416428 let rows_clone = Rc :: clone ( & self . rows ) ;
417429 let row_data = rows_clone. as_ref ( ) . borrow ( ) ;
418- let first_col_data = row_data. get ( & self . columns . first ( ) . unwrap ( ) . column_name ) . unwrap ( ) ;
430+ let first_col_data = row_data
431+ . get ( & self . columns . first ( ) . unwrap ( ) . column_name )
432+ . unwrap ( ) ;
419433 let num_rows = first_col_data. count ( ) ;
420434 let mut print_table_rows: Vec < PrintRow > = vec ! [ PrintRow :: new( vec![ ] ) ; num_rows] ;
421435
@@ -426,9 +440,9 @@ impl Table {
426440 let columns: Vec < String > = col_val. get_serialized_col_data ( ) ;
427441
428442 for i in 0 ..num_rows {
429- if let Some ( cell) = & columns. get ( i) {
443+ if let Some ( cell) = & columns. get ( i) {
430444 print_table_rows[ i] . add_cell ( PrintCell :: new ( cell) ) ;
431- } else {
445+ } else {
432446 print_table_rows[ i] . add_cell ( PrintCell :: new ( "" ) ) ;
433447 }
434448 }
@@ -524,10 +538,10 @@ pub enum Row {
524538impl Row {
525539 fn get_serialized_col_data ( & self ) -> Vec < String > {
526540 match self {
527- Row :: Integer ( cd) => cd. iter ( ) . map ( |( i , v) | v. to_string ( ) ) . collect ( ) ,
528- Row :: Real ( cd) => cd. iter ( ) . map ( |( i , v) | v. to_string ( ) ) . collect ( ) ,
529- Row :: Text ( cd) => cd. iter ( ) . map ( |( i , v) | v. to_string ( ) ) . collect ( ) ,
530- Row :: Bool ( cd) => cd. iter ( ) . map ( |( i , v) | v. to_string ( ) ) . collect ( ) ,
541+ Row :: Integer ( cd) => cd. iter ( ) . map ( |( _i , v) | v. to_string ( ) ) . collect ( ) ,
542+ Row :: Real ( cd) => cd. iter ( ) . map ( |( _i , v) | v. to_string ( ) ) . collect ( ) ,
543+ Row :: Text ( cd) => cd. iter ( ) . map ( |( _i , v) | v. to_string ( ) ) . collect ( ) ,
544+ Row :: Bool ( cd) => cd. iter ( ) . map ( |( _i , v) | v. to_string ( ) ) . collect ( ) ,
531545 Row :: None => panic ! ( "Found None in columns" ) ,
532546 }
533547 }
@@ -591,16 +605,18 @@ mod tests {
591605 assert_eq ! ( table. last_rowid, 0 ) ;
592606
593607 let id_column = "id" . to_string ( ) ;
594- if let Some ( column) = table. columns
608+ if let Some ( column) = table
609+ . columns
595610 . iter ( )
596611 . filter ( |c| c. column_name == id_column)
597612 . collect :: < Vec < & Column > > ( )
598- . first ( ) {
599- assert_eq ! ( column. is_pk, true ) ;
600- assert_eq ! ( column. datatype, DataType :: Integer ) ;
601- } else {
602- panic ! ( "column not found" ) ;
603- }
613+ . first ( )
614+ {
615+ assert_eq ! ( column. is_pk, true ) ;
616+ assert_eq ! ( column. datatype, DataType :: Integer ) ;
617+ } else {
618+ panic ! ( "column not found" ) ;
619+ }
604620 }
605621
606622 #[ test]
0 commit comments