22
33use std:: {
44 path:: { Path , PathBuf } ,
5- str:: FromStr ,
5+ str:: FromStr , vec ,
66} ;
77
88use crate :: {
@@ -49,6 +49,7 @@ enum SqlFileDocSource<'a> {
4949 File ( PathBuf ) ,
5050 Files ( Vec < PathBuf > ) ,
5151 FromString ( & ' a str ) ,
52+ FromStringsWithPaths ( & ' a [ ( String , PathBuf ) ] )
5253}
5354
5455impl SqlDoc {
@@ -97,6 +98,17 @@ impl SqlDoc {
9798 }
9899 }
99100
101+ /// Creates a builder from a vec of tuples containing the `sql` as [`String`] and the path as [`PathBuf`]
102+ #[ must_use]
103+ pub const fn builder_from_strs_with_paths ( string_with_path : & [ ( String , PathBuf ) ] ) -> SqlDocBuilder < ' _ > {
104+ SqlDocBuilder {
105+ source : SqlFileDocSource :: FromStringsWithPaths ( string_with_path) ,
106+ deny : Vec :: new ( ) ,
107+ multiline_flat : MultiFlatten :: NoFlat
108+ }
109+ }
110+
111+
100112 /// Method for finding a specific [`TableDoc`] by `name`
101113 ///
102114 /// # Parameters
@@ -209,9 +221,10 @@ impl SqlDocBuilder<'_> {
209221 vec ! [ sql_doc]
210222 }
211223 SqlFileDocSource :: FromString ( content) => {
212- let sql_docs = generate_docs_str ( content) ?;
224+ let sql_docs = generate_docs_str ( content, None ) ?;
213225 vec ! [ sql_docs]
214- }
226+ } ,
227+ SqlFileDocSource :: FromStringsWithPaths ( strings_paths ) => generate_docs_from_strs_with_paths ( strings_paths) ?,
215228 SqlFileDocSource :: Files ( files) => generate_docs_from_files ( files) ?,
216229 } ;
217230 let num_of_tables = docs. iter ( ) . map ( super :: docs:: SqlFileDoc :: number_of_tables) . sum ( ) ;
@@ -269,7 +282,7 @@ fn generate_docs_from_dir<P: AsRef<Path>, S: AsRef<str>>(
269282 let deny_list: Vec < String > = deny. iter ( ) . map ( |file| file. as_ref ( ) . to_owned ( ) ) . collect ( ) ;
270283 let file_set = SqlFilesList :: new ( source, & deny_list) ?;
271284 let mut sql_docs = Vec :: new ( ) ;
272- for file in file_set. sql_files_sorted ( ) {
285+ for file in file_set. sql_files ( ) {
273286 let docs = generate_docs_from_file ( file) ?;
274287 sql_docs. push ( docs) ;
275288 }
@@ -293,14 +306,23 @@ fn generate_docs_from_file<P: AsRef<Path>>(source: P) -> Result<SqlFileDoc, DocE
293306 Ok ( docs)
294307}
295308
296- fn generate_docs_str ( content : & str ) -> Result < SqlFileDoc , DocError > {
297- let dummy_file = SqlFile :: new_from_str ( content. to_owned ( ) ) ;
309+ fn generate_docs_str ( content : & str , path : Option < PathBuf > ) -> Result < SqlFileDoc , DocError > {
310+ let dummy_file = SqlFile :: new_from_str ( content. to_owned ( ) , path ) ;
298311 let parsed_sql = ParsedSqlFile :: parse ( dummy_file) ?;
299312 let comments = Comments :: parse_all_comments_from_file ( & parsed_sql) ?;
300313 let docs = SqlFileDoc :: from_parsed_file ( & parsed_sql, & comments) ?;
301314 Ok ( docs)
302315}
303316
317+ fn generate_docs_from_strs_with_paths ( strings_with_paths : & [ ( String , PathBuf ) ] ) -> Result < Vec < SqlFileDoc > , DocError > {
318+ let mut docs = Vec :: new ( ) ;
319+ for ( content, path) in strings_with_paths {
320+ docs. push ( generate_docs_str ( content, Some ( path. to_owned ( ) ) ) ?) ;
321+ }
322+
323+ Ok ( docs)
324+ }
325+
304326#[ cfg( test) ]
305327mod tests {
306328 use std:: {
0 commit comments