@@ -6,7 +6,7 @@ use crate::exports::stargazers::db::user::Guest as UserGuest;
66use exports:: stargazers:: db:: user:: { Ordering , Stargazer } ;
77use humantime:: format_rfc3339_millis;
88use turso:: request:: { NamedArg , PipelineAction , PipelineRequest , Stmt } ;
9- use turso:: response:: { extract_first_value_from_nth_response , QueryResult , Response } ;
9+ use turso:: response:: { QueryResult , Response , extract_first_value_from_nth_response } ;
1010use turso:: { TursoClient , TursoValue } ;
1111use wit_bindgen:: generate;
1212
@@ -54,7 +54,9 @@ fn get_user_description_and_star_status(
5454 // Check if the user already starred the repo
5555 PipelineAction :: Execute {
5656 stmt: Stmt {
57- sql: format!( "SELECT 1 FROM stars WHERE user_name = :{PARAM_LOGIN} AND repo_name = :{PARAM_REPO}" ) ,
57+ sql: format!(
58+ "SELECT 1 FROM stars WHERE user_name = :{PARAM_LOGIN} AND repo_name = :{PARAM_REPO}"
59+ ) ,
5860 named_args: vec![
5961 NamedArg {
6062 name: PARAM_LOGIN ,
@@ -75,14 +77,12 @@ fn get_user_description_and_star_status(
7577 PipelineAction :: Execute {
7678 stmt: Stmt {
7779 sql: format!( "SELECT description FROM users WHERE name = :{PARAM_LOGIN}" ) ,
78- named_args: vec![
79- NamedArg {
80- name: PARAM_LOGIN ,
81- value: TursoValue :: Text {
82- value: login. to_string( ) ,
83- } ,
80+ named_args: vec![ NamedArg {
81+ name: PARAM_LOGIN ,
82+ value: TursoValue :: Text {
83+ value: login. to_string( ) ,
8484 } ,
85- ]
85+ } ] ,
8686 } ,
8787 } ,
8888 PipelineAction :: Close ,
@@ -104,14 +104,14 @@ fn parse_user_description_and_star_status(
104104 }
105105 resp. pop ( ) . unwrap ( ) ; // Close
106106 let description = resp. pop ( ) . unwrap ( ) ; // Select user's description
107- // Check if the user already starred the repo
107+ // Check if the user already starred the repo
108108 let already_starred = match extract_first_value_from_nth_response ( resp, 0 ) ? {
109109 TursoValue :: Integer { .. } => true ,
110110 TursoValue :: Null => false ,
111111 other => {
112112 return Err ( format ! (
113113 "unexpected data type, expected Integer or Null, got {other:?}"
114- ) )
114+ ) ) ;
115115 }
116116 } ;
117117 // Get the user's description
@@ -121,7 +121,7 @@ fn parse_user_description_and_star_status(
121121 other => {
122122 return Err ( format ! (
123123 "unexpected data type, expected Text or Null, got {other:?}"
124- ) )
124+ ) ) ;
125125 }
126126 } ;
127127 Ok ( ( description, already_starred) )
@@ -144,10 +144,12 @@ impl UserGuest for Component {
144144 // Add user: if the user already exists and did not have a star relation to the repo, update the `updated_at` field.
145145 PipelineAction :: Execute {
146146 stmt: Stmt {
147- sql: format!( "INSERT INTO users (name, updated_at) VALUES
147+ sql: format!(
148+ "INSERT INTO users (name, updated_at) VALUES
148149 (:{PARAM_LOGIN}, :{PARAM_NOW}) \
149150 ON CONFLICT(name) DO UPDATE \
150- SET updated_at = :{PARAM_NOW}") ,
151+ SET updated_at = :{PARAM_NOW}"
152+ ) ,
151153 named_args: vec![
152154 NamedArg {
153155 name: PARAM_LOGIN ,
@@ -157,32 +159,32 @@ impl UserGuest for Component {
157159 } ,
158160 NamedArg {
159161 name: PARAM_NOW ,
160- value: TursoValue :: Text {
161- value: now. clone( )
162- }
163- }
162+ value: TursoValue :: Text { value: now. clone( ) } ,
163+ } ,
164164 ] ,
165165 } ,
166166 } ,
167167 // Add repo if it does not exist.
168168 PipelineAction :: Execute {
169169 stmt: Stmt {
170- sql: format!( "INSERT INTO repos (name) VALUES (:{PARAM_REPO}) ON CONFLICT DO NOTHING;" ) ,
171- named_args : vec! [
172- NamedArg {
173- name : PARAM_REPO ,
174- value : TursoValue :: Text {
175- value: repo . clone ( ) ,
176- } ,
170+ sql: format!(
171+ "INSERT INTO repos (name) VALUES (:{PARAM_REPO}) ON CONFLICT DO NOTHING;"
172+ ) ,
173+ named_args : vec! [ NamedArg {
174+ name : PARAM_REPO ,
175+ value: TursoValue :: Text {
176+ value : repo . clone ( ) ,
177177 } ,
178- ] ,
178+ } ] ,
179179 } ,
180180 } ,
181181 // Add the star relation
182182 PipelineAction :: Execute {
183183 stmt: Stmt {
184- sql: format!( "INSERT INTO stars (user_name, repo_name) VALUES \
185- (:{PARAM_LOGIN}, :{PARAM_REPO}) ON CONFLICT DO NOTHING;") ,
184+ sql: format!(
185+ "INSERT INTO stars (user_name, repo_name) VALUES \
186+ (:{PARAM_LOGIN}, :{PARAM_REPO}) ON CONFLICT DO NOTHING;"
187+ ) ,
186188 named_args: vec![
187189 NamedArg {
188190 name: PARAM_LOGIN ,
@@ -196,7 +198,6 @@ impl UserGuest for Component {
196198 value: repo. clone( ) ,
197199 } ,
198200 } ,
199-
200201 ] ,
201202 } ,
202203 } ,
@@ -405,8 +406,8 @@ mod tests {
405406 exports:: stargazers:: db:: user:: Stargazer ,
406407 process_resp_list_stargazers,
407408 turso:: {
408- response:: { extract_first_value_from_nth_response, PipelineResponse } ,
409409 TursoValue ,
410+ response:: { PipelineResponse , extract_first_value_from_nth_response} ,
410411 } ,
411412 } ;
412413
@@ -676,30 +677,30 @@ mod tests {
676677
677678 mod integration {
678679 use crate :: {
680+ Component , ENV_TURSO_LOCATION , ENV_TURSO_TOKEN ,
679681 exports:: stargazers:: db:: {
680682 llm:: Guest as _,
681683 user:: { Guest as _, Ordering , Stargazer } ,
682684 } ,
683685 turso:: {
686+ TursoClient , TursoValue ,
684687 request:: { NamedArg , PipelineAction , PipelineRequest , Stmt } ,
685688 response:: { QueryResult , Response } ,
686- TursoClient , TursoValue ,
687689 } ,
688- Component , ENV_TURSO_LOCATION , ENV_TURSO_TOKEN ,
689690 } ;
690691
691692 fn set_up ( ) {
692693 let test_token =
693694 std:: env:: var ( format ! ( "TEST_{ENV_TURSO_TOKEN}" ) ) . unwrap_or_else ( |_| {
694695 panic ! ( "TEST_{ENV_TURSO_TOKEN} must be set as an environment variable" )
695696 } ) ;
696- std:: env:: set_var ( ENV_TURSO_TOKEN , test_token) ;
697+ unsafe { std:: env:: set_var ( ENV_TURSO_TOKEN , test_token) } ;
697698
698699 let test_location =
699700 std:: env:: var ( format ! ( "TEST_{ENV_TURSO_LOCATION}" ) ) . unwrap_or_else ( |_| {
700701 panic ! ( "TEST_{ENV_TURSO_LOCATION} must be set as an environment variable" )
701702 } ) ;
702- std:: env:: set_var ( ENV_TURSO_LOCATION , test_location) ;
703+ unsafe { std:: env:: set_var ( ENV_TURSO_LOCATION , test_location) } ;
703704 }
704705
705706 fn random_string ( ) -> String {
0 commit comments