@@ -13,7 +13,7 @@ use std::time::Duration;
1313#[ derive( Parser , Debug ) ]
1414#[ command( name = "nexum" ) ]
1515#[ command( author = "Aviral Garg" ) ]
16- #[ command( version = "0.4.0" ) ]
16+ #[ command( version = env! ( "CARGO_PKG_VERSION" ) ) ]
1717#[ command( about = "An AI-native database combining SQL with semantic caching and NL queries" ) ]
1818#[ command( long_about = r#"
1919NexumDB is an innovative, open-source database that combines traditional SQL
@@ -115,8 +115,8 @@ fn main() -> anyhow::Result<()> {
115115 continue ;
116116 }
117117
118- if input. to_uppercase ( ) . starts_with ( "ASK " ) {
119- let natural_query = input [ 4 .. ] . trim ( ) ;
118+ if let Some ( natural_query ) = input. strip_prefix ( "ASK " ) . or_else ( || input . strip_prefix ( "ask " ) ) {
119+ let natural_query = natural_query . trim ( ) ;
120120
121121 if let Some ( ref translator) = nl_translator {
122122 let schema = get_schema_context ( & catalog) ;
@@ -158,8 +158,8 @@ fn main() -> anyhow::Result<()> {
158158 }
159159
160160 // Handle EXPLAIN command
161- if input. to_uppercase ( ) . starts_with ( "EXPLAIN " ) {
162- let query_to_explain = input [ 8 .. ] . trim ( ) ;
161+ if let Some ( query_to_explain ) = input. strip_prefix ( "EXPLAIN " ) . or_else ( || input . strip_prefix ( "explain " ) ) {
162+ let query_to_explain = query_to_explain . trim ( ) ;
163163
164164 if let Some ( ref explainer) = query_explainer {
165165 println ! ( ) ;
@@ -205,14 +205,14 @@ fn print_banner() {
205205 | \ | | _____ ___ _ _ __ | _ \| __ )
206206 | \| |/ _ \ \/ / | | | '_ \| | | | _ \
207207 | |\ | __/> <| |_| | | | | |_| | |_) |
208- |_| \_|\___/_/\_\\ __,_|_| |_|____/|____/
208+ |_| \_|\___/_/\_\__,_|_| |_|____/|____/
209209"#
210210 . cyan( )
211211 . bold( )
212212 ) ;
213213 println ! (
214214 " {} {}" ,
215- "v0.4.0" . yellow( ) ,
215+ format! ( "v{}" , env! ( "CARGO_PKG_VERSION" ) ) . yellow( ) ,
216216 "- AI-Native Database with Natural Language Support" . white( )
217217 ) ;
218218 println ! ( ) ;
@@ -385,9 +385,12 @@ fn print_result_json(result: &ExecutionResult) {
385385 . map ( |row| {
386386 let mut obj = serde_json:: Map :: new ( ) ;
387387 for ( i, col) in columns. iter ( ) . enumerate ( ) {
388- if i < row. values . len ( ) {
389- obj. insert ( col. clone ( ) , value_to_json ( & row. values [ i] ) ) ;
390- }
388+ let value = if i < row. values . len ( ) {
389+ value_to_json ( & row. values [ i] )
390+ } else {
391+ serde_json:: Value :: Null
392+ } ;
393+ obj. insert ( col. clone ( ) , value) ;
391394 }
392395 serde_json:: Value :: Object ( obj)
393396 } )
@@ -439,7 +442,7 @@ fn print_result_json(result: &ExecutionResult) {
439442 } )
440443 }
441444 } ;
442- println ! ( "{}" , serde_json:: to_string_pretty( & json) . unwrap ( ) ) ;
445+ println ! ( "{}" , serde_json:: to_string_pretty( & json) . unwrap_or_else ( |e| format! ( "{{ \" error \" : \" {} \" }}" , e ) ) ) ;
443446}
444447
445448fn print_result_formatted ( result : & ExecutionResult ) {
@@ -533,7 +536,20 @@ fn format_value(value: &nexum_core::sql::types::Value) -> String {
533536fn value_to_json ( value : & nexum_core:: sql:: types:: Value ) -> serde_json:: Value {
534537 match value {
535538 nexum_core:: sql:: types:: Value :: Integer ( i) => serde_json:: json!( i) ,
536- nexum_core:: sql:: types:: Value :: Float ( f) => serde_json:: json!( f) ,
539+ nexum_core:: sql:: types:: Value :: Float ( f) => {
540+ // Handle NaN and Infinity which are not valid JSON
541+ if f. is_nan ( ) {
542+ serde_json:: json!( "NaN" )
543+ } else if f. is_infinite ( ) {
544+ if * f > 0.0 {
545+ serde_json:: json!( "Infinity" )
546+ } else {
547+ serde_json:: json!( "-Infinity" )
548+ }
549+ } else {
550+ serde_json:: json!( f)
551+ }
552+ }
537553 nexum_core:: sql:: types:: Value :: Text ( t) => serde_json:: json!( t) ,
538554 nexum_core:: sql:: types:: Value :: Boolean ( b) => serde_json:: json!( b) ,
539555 nexum_core:: sql:: types:: Value :: Null => serde_json:: Value :: Null ,
0 commit comments