Skip to content

Commit

Permalink
Fix documentation (#5)
Browse files Browse the repository at this point in the history
* remove debug print

* fix use sqlparser in documentation
  • Loading branch information
takaebato authored Feb 12, 2024
1 parent 0f3f748 commit 1c7b94f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sql-insight = { version = "0.1.0" }
Format SQL queries according to different dialects:

```rust
use sqlparser::dialect::GenericDialect;
use sql_insight::sqlparser::dialect::GenericDialect;

let dialect = GenericDialect {};
let formatted_sql = sql_insight::format(&dialect, "SELECT * \n from users WHERE id = 1").unwrap();
Expand All @@ -44,7 +44,7 @@ assert_eq!(formatted_sql, ["SELECT * FROM users WHERE id = 1"]);
Normalize SQL queries to abstract away literals:

```rust
use sqlparser::dialect::GenericDialect;
use sql_insight::sqlparser::dialect::GenericDialect;

let dialect = GenericDialect {};
let normalized_sql = sql_insight::normalize(&dialect, "SELECT * \n from users WHERE id = 1").unwrap();
Expand All @@ -56,7 +56,7 @@ assert_eq!(normalized_sql, ["SELECT * FROM users WHERE id = ?"]);
Extract table references from SQL queries:

```rust
use sqlparser::dialect::GenericDialect;
use sql_insight::sqlparser::dialect::GenericDialect;

let dialect = GenericDialect {};
let tables = sql_insight::extract_tables(&dialect, "SELECT * FROM catalog.schema.`users` as users_alias").unwrap();
Expand All @@ -74,7 +74,7 @@ This outputs:
Identify CRUD operations and the tables involved in each operation within SQL queries:

```rust
use sqlparser::dialect::GenericDialect;
use sql_insight::sqlparser::dialect::GenericDialect;

let dialect = GenericDialect {};
let crud_tables = sql_insight::extract_crud_tables(&dialect, "INSERT INTO users (name) SELECT name FROM employees").unwrap();
Expand Down
4 changes: 1 addition & 3 deletions sql-insight/src/extractor/crud_table_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use sqlparser::parser::Parser;
/// ## Example
///
/// ```rust
/// use sqlparser::dialect::GenericDialect;
/// use sql_insight::sqlparser::dialect::GenericDialect;
///
/// let dialect = GenericDialect {};
/// let sql = "INSERT INTO t1 (a) SELECT a FROM t2";
Expand Down Expand Up @@ -128,8 +128,6 @@ impl Visitor for CrudTableExtractor {
self.possibly_aliased_delete_tables.clone(),
self.read_tables.clone(),
);
println!("delete_tables: {:?}", self.delete_tables);
println!("read_tables: {:?}", self.read_tables);
self.read_tables = helper::calc_difference_of_tables(
self.read_tables.clone(),
self.delete_tables.clone(),
Expand Down
2 changes: 1 addition & 1 deletion sql-insight/src/extractor/table_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sqlparser::parser::Parser;
/// ## Example
///
/// ```rust
/// use sqlparser::dialect::GenericDialect;
/// use sql_insight::sqlparser::dialect::GenericDialect;
///
/// let dialect = GenericDialect {};
/// let sql = "SELECT a FROM t1 INNER JOIN t2 ON t1.id = t2.id";
Expand Down
2 changes: 1 addition & 1 deletion sql-insight/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sqlparser::parser::Parser;
/// ## Example
///
/// ```rust
/// use sqlparser::dialect::GenericDialect;
/// use sql_insight::sqlparser::dialect::GenericDialect;
///
/// let dialect = GenericDialect {};
/// let sql = "SELECT a FROM t1 \n WHERE b = 1";
Expand Down
2 changes: 1 addition & 1 deletion sql-insight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! Here's a quick example to get you started with SQL formatting:
//!
//! ```rust
//! use sqlparser::dialect::GenericDialect;
//! use sql_insight::sqlparser::dialect::GenericDialect;
//!
//! let dialect = GenericDialect {};
//! let normalized_sql = sql_insight::format(&dialect, "SELECT * \n from users WHERE id = 1").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions sql-insight/src/normalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sqlparser::parser::Parser;
/// ## Example
///
/// ```rust
/// use sqlparser::dialect::GenericDialect;
/// use sql_insight::sqlparser::dialect::GenericDialect;
///
/// let dialect = GenericDialect {};
/// let sql = "SELECT a FROM t1 WHERE b = 1 AND c in (2, 3) AND d LIKE '%foo'";
Expand All @@ -31,7 +31,7 @@ pub fn normalize(dialect: &dyn Dialect, sql: &str) -> Result<Vec<String>, Error>
/// ## Example
///
/// ```rust
/// use sqlparser::dialect::GenericDialect;
/// use sql_insight::sqlparser::dialect::GenericDialect;
/// use sql_insight::NormalizerOptions;
///
/// let dialect = GenericDialect {};
Expand Down

0 comments on commit 1c7b94f

Please sign in to comment.