11//! Public entry point for building [`SqlDoc`] from a directory, file, or string.
22
3- use std:: path:: { Path , PathBuf } ;
3+ use std:: { path:: { Path , PathBuf } , str :: FromStr } ;
44
55use crate :: {
66 ast:: ParsedSqlFile ,
@@ -72,7 +72,7 @@ impl SqlDoc {
7272
7373 /// Creates a builder from SQL text (no filesystem path is associated) from a [`str`]
7474 #[ must_use]
75- pub const fn from_str ( content : & str ) -> SqlDocBuilder < ' _ > {
75+ pub const fn builder_from_str ( content : & str ) -> SqlDocBuilder < ' _ > {
7676 SqlDocBuilder {
7777 source : SqlFileDocSource :: FromString ( content) ,
7878 deny : Vec :: new ( ) ,
@@ -144,6 +144,14 @@ impl SqlDoc {
144144 }
145145}
146146
147+ impl FromStr for SqlDoc {
148+ type Err = DocError ;
149+
150+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
151+ SqlDoc :: builder_from_str ( s) . build ( )
152+ }
153+ }
154+
147155impl SqlDocBuilder < ' _ > {
148156 /// Method for adding an item to the deny list
149157 ///
@@ -675,7 +683,7 @@ mod tests {
675683 fn test_sql_doc_from_str_builds_expected_builder ( ) {
676684 let content = "CREATE TABLE t(id INTEGER);" ;
677685
678- let actual = SqlDoc :: from_str ( content) ;
686+ let actual = SqlDoc :: builder_from_str ( content) ;
679687
680688 let expected = SqlDocBuilder {
681689 source : crate :: sql_doc:: SqlFileDocSource :: FromString ( content) ,
@@ -685,4 +693,12 @@ mod tests {
685693
686694 assert_eq ! ( actual, expected) ;
687695 }
696+
697+ #[ test]
698+ fn test_fromstr_parse_sql_doc ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
699+ let doc: SqlDoc = "CREATE TABLE t(id INTEGER);" . parse ( ) ?;
700+ assert_eq ! ( doc. tables( ) . len( ) , 1 ) ;
701+ Ok ( ( ) )
702+ }
703+
688704}
0 commit comments