pygosqlx 1.16.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pygosqlx/__init__.py +124 -0
- pygosqlx/core.py +821 -0
- pygosqlx/exceptions.py +69 -0
- pygosqlx/lib/libgosqlx.dll +0 -0
- pygosqlx/lib/libgosqlx.h +117 -0
- pygosqlx/py.typed +0 -0
- pygosqlx-1.16.0.dist-info/METADATA +374 -0
- pygosqlx-1.16.0.dist-info/RECORD +11 -0
- pygosqlx-1.16.0.dist-info/WHEEL +5 -0
- pygosqlx-1.16.0.dist-info/licenses/LICENSE +202 -0
- pygosqlx-1.16.0.dist-info/top_level.txt +1 -0
pygosqlx/__init__.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""PyGoSQLX - Python bindings for GoSQLX SQL parser.
|
|
2
|
+
|
|
3
|
+
A high-performance SQL parser powered by GoSQLX's Go engine.
|
|
4
|
+
100x+ faster than pure Python SQL parsers.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
import pygosqlx
|
|
8
|
+
|
|
9
|
+
# Parse SQL
|
|
10
|
+
result = pygosqlx.parse("SELECT * FROM users")
|
|
11
|
+
print(result.statement_types) # ['SELECT']
|
|
12
|
+
|
|
13
|
+
# Validate SQL
|
|
14
|
+
is_valid = pygosqlx.validate("SELECT * FROM users")
|
|
15
|
+
print(is_valid) # True
|
|
16
|
+
|
|
17
|
+
# Validate with details
|
|
18
|
+
result = pygosqlx.validate_detailed("SELECT * FROM")
|
|
19
|
+
if not result.valid:
|
|
20
|
+
print(result.error)
|
|
21
|
+
|
|
22
|
+
# Format SQL
|
|
23
|
+
formatted = pygosqlx.format("select * from users")
|
|
24
|
+
print(formatted)
|
|
25
|
+
|
|
26
|
+
# Extract tables
|
|
27
|
+
tables = pygosqlx.extract_tables("SELECT * FROM users JOIN orders ON ...")
|
|
28
|
+
print(tables) # ['users', 'orders']
|
|
29
|
+
|
|
30
|
+
# Extract columns
|
|
31
|
+
columns = pygosqlx.extract_columns("SELECT name, email FROM users")
|
|
32
|
+
print(columns) # ['name', 'email']
|
|
33
|
+
|
|
34
|
+
# Extract functions
|
|
35
|
+
functions = pygosqlx.extract_functions("SELECT COUNT(*), UPPER(name) FROM users")
|
|
36
|
+
print(functions) # ['COUNT', 'UPPER']
|
|
37
|
+
|
|
38
|
+
# Extract all metadata
|
|
39
|
+
metadata = pygosqlx.extract_metadata("SELECT COUNT(*) FROM users u JOIN orders o ON u.id = o.user_id")
|
|
40
|
+
print(metadata.tables) # ['users', 'orders']
|
|
41
|
+
print(metadata.functions) # ['COUNT']
|
|
42
|
+
|
|
43
|
+
# Dialect-aware parsing (every function above accepts dialect=)
|
|
44
|
+
pygosqlx.parse("SELECT TOP 5 [id] FROM [users]", dialect="sqlserver")
|
|
45
|
+
print(pygosqlx.dialects()) # ['generic', 'postgresql', 'mysql', ...]
|
|
46
|
+
|
|
47
|
+
# Lint with the `gosqlx lint` rule set (L001-L010)
|
|
48
|
+
for v in pygosqlx.lint("select id from users").violations:
|
|
49
|
+
print(v.rule, v.message)
|
|
50
|
+
|
|
51
|
+
# Scan for SQL injection patterns
|
|
52
|
+
scan = pygosqlx.security_scan("SELECT * FROM users WHERE id = 1 OR 1=1 --")
|
|
53
|
+
print(scan.is_clean, scan.has_critical)
|
|
54
|
+
|
|
55
|
+
# Convert between dialects
|
|
56
|
+
print(pygosqlx.transpile("CREATE TABLE t (id INT AUTO_INCREMENT PRIMARY KEY)",
|
|
57
|
+
"mysql", "postgresql"))
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
from pygosqlx.core import (
|
|
61
|
+
LintResult,
|
|
62
|
+
LintViolation,
|
|
63
|
+
Metadata,
|
|
64
|
+
ParseResult,
|
|
65
|
+
QualifiedName,
|
|
66
|
+
SecurityFinding,
|
|
67
|
+
SecurityScanResult,
|
|
68
|
+
ValidationResult,
|
|
69
|
+
dialects,
|
|
70
|
+
extract_columns,
|
|
71
|
+
extract_functions,
|
|
72
|
+
extract_metadata,
|
|
73
|
+
extract_tables,
|
|
74
|
+
format,
|
|
75
|
+
lint,
|
|
76
|
+
parse,
|
|
77
|
+
security_scan,
|
|
78
|
+
transpile,
|
|
79
|
+
validate,
|
|
80
|
+
validate_detailed,
|
|
81
|
+
version,
|
|
82
|
+
)
|
|
83
|
+
from pygosqlx.exceptions import (
|
|
84
|
+
FormatError,
|
|
85
|
+
GoSQLXError,
|
|
86
|
+
ParseError,
|
|
87
|
+
TranspileError,
|
|
88
|
+
UnsupportedDialectError,
|
|
89
|
+
ValidationError,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
__version__ = "1.16.0"
|
|
93
|
+
__all__ = [
|
|
94
|
+
# Functions
|
|
95
|
+
"parse",
|
|
96
|
+
"validate",
|
|
97
|
+
"validate_detailed",
|
|
98
|
+
"format",
|
|
99
|
+
"extract_tables",
|
|
100
|
+
"extract_columns",
|
|
101
|
+
"extract_functions",
|
|
102
|
+
"extract_metadata",
|
|
103
|
+
"lint",
|
|
104
|
+
"security_scan",
|
|
105
|
+
"transpile",
|
|
106
|
+
"dialects",
|
|
107
|
+
"version",
|
|
108
|
+
# Data types
|
|
109
|
+
"ParseResult",
|
|
110
|
+
"ValidationResult",
|
|
111
|
+
"Metadata",
|
|
112
|
+
"QualifiedName",
|
|
113
|
+
"LintResult",
|
|
114
|
+
"LintViolation",
|
|
115
|
+
"SecurityScanResult",
|
|
116
|
+
"SecurityFinding",
|
|
117
|
+
# Exceptions
|
|
118
|
+
"GoSQLXError",
|
|
119
|
+
"ParseError",
|
|
120
|
+
"FormatError",
|
|
121
|
+
"ValidationError",
|
|
122
|
+
"TranspileError",
|
|
123
|
+
"UnsupportedDialectError",
|
|
124
|
+
]
|