@@ -34,60 +34,7 @@ CREATE TABLE users (
3434```
3535A rudimentary implementation can be generated with:
3636``` rust
37- #![cfg(feature = " std" )]
38- use sql_docs :: {GenericDialect ,SqlDoc ,error :: DocError };
39- use std :: {env, fs};
40-
41- fn main () -> Result <(), DocError > {
42- // Temporary directory and file created for demonstration purposes
43- let base = env :: temp_dir (). join (" tmp_dir" );
44- let _ = fs :: remove_dir_all (& base );
45- fs :: create_dir_all (& base )? ;
46- let example = base . join (" example.sql" );
47-
48- fs :: write (
49- & example ,
50- r # " -- Table storing user accounts
51- -- Contains all user values
52- /* Rows generated at registration */
53- CREATE TABLE users (
54- /* Primary key for each user */
55- id INTEGER PRIMARY KEY,
56- -- The user's login name
57- username VARCHAR(255) NOT NULL,
58- /* User's email address */
59- email VARCHAR(255) UNIQUE NOT NULL
60- );" # ,
61- )? ;
62-
63- // Extract documentation from a single file
64- let docs = SqlDoc :: from_path (& example )
65- // Capture all valid comment lines preceding the statements directly
66- . collect_all_leading ()
67- // Replace `\n` with a `str`
68- . flatten_multiline_with (" . " )
69- // Finally build the `SqlDoc`
70- . build :: <GenericDialect >()? ;
71- // Or extract recursively from a directory
72- // let docs = SqlDoc::from_dir(&base).build()?;
73-
74- // Retrieve a specific table
75- let users = docs . table (" users" , None )? ;
76-
77- // Table name
78- assert_eq! (users . name (), " users" );
79- // Optional table-level documentation
80- assert_eq! (users . doc (), Some (" Table storing user accounts. Contains all user values. Rows generated at registration" ));
81- // Path to the source file
82- assert_eq! (users . path (), Some (example . as_ref ()));
83-
84- let _ = fs :: remove_dir_all (& base );
85- Ok (())
86- }
87- ```
88-
89- Or with no ` std ` and from a ` String ` :
90- ``` rust
37+ #![cfg(not(feature = " std" ))]
9138use sql_docs :: {GenericDialect ,SqlDoc ,error :: DocError };
9239
9340fn main () -> Result <(), DocError > {
@@ -106,7 +53,7 @@ CREATE TABLE users (
10653);" # ;
10754
10855 // Extract documentation from a single file
109- let docs = SqlDoc :: from (& example )
56+ let docs = SqlDoc :: builder_from_str (& example )
11057 // Capture all valid comment lines preceding the statements directly
11158 . collect_all_leading ()
11259 // Replace `\n` with a `str`
@@ -124,7 +71,7 @@ CREATE TABLE users (
12471 // Optional table-level documentation
12572 assert_eq! (users . doc (), Some (" Table storing user accounts. Contains all user values. Rows generated at registration" ));
12673 Ok (())
127- }
74+ }
12875```
12976## Primary Interface (Main API)
13077
0 commit comments