velocity-python 0.0.131__py3-none-any.whl → 0.0.132__py3-none-any.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.
Potentially problematic release.
This version of velocity-python might be problematic. Click here for more details.
- velocity/__init__.py +1 -1
- velocity/db/servers/base/__init__.py +9 -0
- velocity/db/servers/base/initializer.py +69 -0
- velocity/db/servers/base/operators.py +98 -0
- velocity/db/servers/base/sql.py +503 -0
- velocity/db/servers/base/types.py +135 -0
- velocity/db/servers/mysql/__init__.py +64 -0
- velocity/db/servers/mysql/operators.py +54 -0
- velocity/db/servers/{mysql_reserved.py → mysql/reserved.py} +2 -14
- velocity/db/servers/mysql/sql.py +569 -0
- velocity/db/servers/mysql/types.py +107 -0
- velocity/db/servers/postgres/__init__.py +40 -0
- velocity/db/servers/postgres/operators.py +34 -0
- velocity/db/servers/postgres/sql.py +4 -3
- velocity/db/servers/postgres/types.py +88 -2
- velocity/db/servers/sqlite/__init__.py +52 -0
- velocity/db/servers/sqlite/operators.py +52 -0
- velocity/db/servers/sqlite/reserved.py +20 -0
- velocity/db/servers/sqlite/sql.py +530 -0
- velocity/db/servers/sqlite/types.py +92 -0
- velocity/db/servers/sqlserver/__init__.py +64 -0
- velocity/db/servers/sqlserver/operators.py +47 -0
- velocity/db/servers/sqlserver/reserved.py +32 -0
- velocity/db/servers/sqlserver/sql.py +625 -0
- velocity/db/servers/sqlserver/types.py +114 -0
- {velocity_python-0.0.131.dist-info → velocity_python-0.0.132.dist-info}/METADATA +1 -1
- {velocity_python-0.0.131.dist-info → velocity_python-0.0.132.dist-info}/RECORD +30 -16
- velocity/db/servers/mysql.py +0 -640
- velocity/db/servers/sqlite.py +0 -968
- velocity/db/servers/sqlite_reserved.py +0 -208
- velocity/db/servers/sqlserver.py +0 -921
- velocity/db/servers/sqlserver_reserved.py +0 -314
- {velocity_python-0.0.131.dist-info → velocity_python-0.0.132.dist-info}/WHEEL +0 -0
- {velocity_python-0.0.131.dist-info → velocity_python-0.0.132.dist-info}/licenses/LICENSE +0 -0
- {velocity_python-0.0.131.dist-info → velocity_python-0.0.132.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Abstract base class for database type mapping implementations.
|
|
3
|
+
"""
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
5
|
+
from typing import Any, Type, Union
|
|
6
|
+
import datetime
|
|
7
|
+
import decimal
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BaseTypes(ABC):
|
|
11
|
+
"""
|
|
12
|
+
Abstract base class that defines the interface for database type mappings.
|
|
13
|
+
|
|
14
|
+
Each database implementation should provide concrete implementations of these
|
|
15
|
+
type mapping methods to handle conversion between Python types and SQL types.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
# Basic SQL type constants - should be overridden by subclasses
|
|
19
|
+
TEXT: str = "TEXT"
|
|
20
|
+
INTEGER: str = "INTEGER"
|
|
21
|
+
NUMERIC: str = "NUMERIC"
|
|
22
|
+
BOOLEAN: str = "BOOLEAN"
|
|
23
|
+
DATE: str = "DATE"
|
|
24
|
+
TIME: str = "TIME"
|
|
25
|
+
DATETIME: str = "DATETIME"
|
|
26
|
+
TIMESTAMP: str = "TIMESTAMP"
|
|
27
|
+
BINARY: str = "BINARY"
|
|
28
|
+
BIGINT: str = "BIGINT"
|
|
29
|
+
SMALLINT: str = "SMALLINT"
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def get_type(cls, v: Any) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Returns a suitable SQL type string for a Python value/object.
|
|
36
|
+
|
|
37
|
+
This method should handle conversion of Python types to appropriate
|
|
38
|
+
SQL column types for table creation and schema operations.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
v: Python value or type to convert
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
SQL type string appropriate for this database
|
|
45
|
+
|
|
46
|
+
Examples:
|
|
47
|
+
get_type(str) -> "TEXT"
|
|
48
|
+
get_type("hello") -> "TEXT"
|
|
49
|
+
get_type(int) -> "INTEGER"
|
|
50
|
+
get_type(123) -> "INTEGER"
|
|
51
|
+
get_type(datetime.datetime.now()) -> "TIMESTAMP"
|
|
52
|
+
"""
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
@abstractmethod
|
|
57
|
+
def get_conv(cls, v: Any) -> str:
|
|
58
|
+
"""
|
|
59
|
+
Returns a base SQL type for expression usage (e.g. CAST operations).
|
|
60
|
+
|
|
61
|
+
This is typically used for CAST expressions and should return
|
|
62
|
+
the fundamental SQL type without precision/scale specifiers.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
v: Python value or type to convert
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
Base SQL type string for casting
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
get_conv(decimal.Decimal("123.45")) -> "NUMERIC"
|
|
72
|
+
get_conv(datetime.datetime.now()) -> "TIMESTAMP"
|
|
73
|
+
"""
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
@abstractmethod
|
|
78
|
+
def py_type(cls, sql_type: str) -> Type:
|
|
79
|
+
"""
|
|
80
|
+
Returns the Python type that corresponds to an SQL type string.
|
|
81
|
+
|
|
82
|
+
This method handles the reverse mapping from SQL types back to
|
|
83
|
+
Python types, typically used when reading schema information.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
sql_type: SQL type string from database schema
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
Corresponding Python type
|
|
90
|
+
|
|
91
|
+
Examples:
|
|
92
|
+
py_type("INTEGER") -> int
|
|
93
|
+
py_type("TEXT") -> str
|
|
94
|
+
py_type("TIMESTAMP") -> datetime.datetime
|
|
95
|
+
|
|
96
|
+
Raises:
|
|
97
|
+
Exception: If the SQL type is not recognized
|
|
98
|
+
"""
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def _handle_special_values(cls, v: Any) -> tuple[bool, str]:
|
|
103
|
+
"""
|
|
104
|
+
Helper method to handle special value prefixes like @@CURRENT_TIMESTAMP.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
v: Value to check
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
Tuple of (is_special, processed_value)
|
|
111
|
+
"""
|
|
112
|
+
if isinstance(v, str) and v.startswith("@@"):
|
|
113
|
+
return True, v[2:] or cls.TEXT
|
|
114
|
+
return False, ""
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def _get_basic_type_mapping(cls) -> dict[Type, str]:
|
|
118
|
+
"""
|
|
119
|
+
Returns basic Python type to SQL type mappings.
|
|
120
|
+
Subclasses can override this to customize mappings.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Dictionary mapping Python types to SQL types
|
|
124
|
+
"""
|
|
125
|
+
return {
|
|
126
|
+
str: cls.TEXT,
|
|
127
|
+
int: cls.INTEGER,
|
|
128
|
+
float: cls.NUMERIC,
|
|
129
|
+
bool: cls.BOOLEAN,
|
|
130
|
+
datetime.datetime: cls.DATETIME,
|
|
131
|
+
datetime.date: cls.DATE,
|
|
132
|
+
datetime.time: cls.TIME,
|
|
133
|
+
decimal.Decimal: cls.NUMERIC,
|
|
134
|
+
bytes: cls.BINARY,
|
|
135
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from ..base.initializer import BaseInitializer
|
|
3
|
+
from velocity.db.core import engine
|
|
4
|
+
from .sql import SQL
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MySQLInitializer(BaseInitializer):
|
|
8
|
+
"""MySQL database initializer."""
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def initialize(config=None, **kwargs):
|
|
12
|
+
"""
|
|
13
|
+
Initialize MySQL engine with mysql.connector driver.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
config: Configuration dictionary
|
|
17
|
+
**kwargs: Additional configuration parameters
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Configured Engine instance
|
|
21
|
+
"""
|
|
22
|
+
try:
|
|
23
|
+
import mysql.connector
|
|
24
|
+
except ImportError:
|
|
25
|
+
raise ImportError(
|
|
26
|
+
"MySQL connector not available. Install with: pip install mysql-connector-python"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Base configuration from environment (if available)
|
|
30
|
+
base_config = {
|
|
31
|
+
"database": os.environ.get("DBDatabase"),
|
|
32
|
+
"host": os.environ.get("DBHost"),
|
|
33
|
+
"port": os.environ.get("DBPort"),
|
|
34
|
+
"user": os.environ.get("DBUser"),
|
|
35
|
+
"password": os.environ.get("DBPassword"),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Remove None values
|
|
39
|
+
base_config = {k: v for k, v in base_config.items() if v is not None}
|
|
40
|
+
|
|
41
|
+
# Set MySQL-specific defaults
|
|
42
|
+
mysql_defaults = {
|
|
43
|
+
"host": "localhost",
|
|
44
|
+
"port": 3306,
|
|
45
|
+
"charset": "utf8mb4",
|
|
46
|
+
"autocommit": False,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# Merge configurations: defaults < env < config < kwargs
|
|
50
|
+
final_config = mysql_defaults.copy()
|
|
51
|
+
final_config.update(base_config)
|
|
52
|
+
final_config = MySQLInitializer._merge_config(final_config, config, **kwargs)
|
|
53
|
+
|
|
54
|
+
# Validate required configuration
|
|
55
|
+
required_keys = ["database", "host", "user"]
|
|
56
|
+
MySQLInitializer._validate_required_config(final_config, required_keys)
|
|
57
|
+
|
|
58
|
+
return engine.Engine(mysql.connector, final_config, SQL)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# Maintain backward compatibility
|
|
62
|
+
def initialize(config=None, **kwargs):
|
|
63
|
+
"""Backward compatible initialization function."""
|
|
64
|
+
return MySQLInitializer.initialize(config, **kwargs)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from ..base.operators import BaseOperators
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MySQLOperators(BaseOperators):
|
|
5
|
+
"""
|
|
6
|
+
MySQL-specific operator mappings.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
@classmethod
|
|
10
|
+
def get_operators(cls):
|
|
11
|
+
"""Returns MySQL-specific operator mappings."""
|
|
12
|
+
return OPERATORS
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
def supports_case_insensitive_like(cls):
|
|
16
|
+
"""MySQL LIKE is case-insensitive by default on case-insensitive collations."""
|
|
17
|
+
return False # Depends on collation, but generally need to use LOWER()
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def supports_regex(cls):
|
|
21
|
+
"""MySQL supports REGEXP/RLIKE operators."""
|
|
22
|
+
return True
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def get_regex_operators(cls):
|
|
26
|
+
"""Returns MySQL regex operators."""
|
|
27
|
+
return {
|
|
28
|
+
"REGEXP": "REGEXP",
|
|
29
|
+
"RLIKE": "RLIKE",
|
|
30
|
+
"NOT REGEXP": "NOT REGEXP",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
OPERATORS = {
|
|
35
|
+
"<>": "<>",
|
|
36
|
+
"!=": "<>",
|
|
37
|
+
"!><": "NOT BETWEEN",
|
|
38
|
+
">!<": "NOT BETWEEN",
|
|
39
|
+
"><": "BETWEEN",
|
|
40
|
+
"%%": "LIKE", # MySQL doesn't have ILIKE, use LIKE with LOWER()
|
|
41
|
+
"!%%": "NOT LIKE",
|
|
42
|
+
"==": "=",
|
|
43
|
+
"<=": "<=",
|
|
44
|
+
">=": ">=",
|
|
45
|
+
"<": "<",
|
|
46
|
+
">": ">",
|
|
47
|
+
"%": "LIKE",
|
|
48
|
+
"!%": "NOT LIKE",
|
|
49
|
+
"=": "=",
|
|
50
|
+
"!": "<>",
|
|
51
|
+
"REGEXP": "REGEXP",
|
|
52
|
+
"!REGEXP": "NOT REGEXP",
|
|
53
|
+
"RLIKE": "RLIKE",
|
|
54
|
+
}
|
|
@@ -61,7 +61,6 @@ reserved_words = [
|
|
|
61
61
|
"ELSEIF",
|
|
62
62
|
"ENCLOSED",
|
|
63
63
|
"ESCAPED",
|
|
64
|
-
"EXCEPT",
|
|
65
64
|
"EXISTS",
|
|
66
65
|
"EXIT",
|
|
67
66
|
"EXPLAIN",
|
|
@@ -75,8 +74,6 @@ reserved_words = [
|
|
|
75
74
|
"FOREIGN",
|
|
76
75
|
"FROM",
|
|
77
76
|
"FULLTEXT",
|
|
78
|
-
"GENERATED",
|
|
79
|
-
"GET",
|
|
80
77
|
"GRANT",
|
|
81
78
|
"GROUP",
|
|
82
79
|
"HAVING",
|
|
@@ -105,7 +102,6 @@ reserved_words = [
|
|
|
105
102
|
"IS",
|
|
106
103
|
"ITERATE",
|
|
107
104
|
"JOIN",
|
|
108
|
-
"JSON",
|
|
109
105
|
"KEY",
|
|
110
106
|
"KEYS",
|
|
111
107
|
"KILL",
|
|
@@ -125,9 +121,7 @@ reserved_words = [
|
|
|
125
121
|
"LONGTEXT",
|
|
126
122
|
"LOOP",
|
|
127
123
|
"LOW_PRIORITY",
|
|
128
|
-
"MASTER_SSL_VERIFY_SERVER_CERT",
|
|
129
124
|
"MATCH",
|
|
130
|
-
"MAXVALUE",
|
|
131
125
|
"MEDIUMBLOB",
|
|
132
126
|
"MEDIUMINT",
|
|
133
127
|
"MEDIUMTEXT",
|
|
@@ -150,7 +144,6 @@ reserved_words = [
|
|
|
150
144
|
"OUT",
|
|
151
145
|
"OUTER",
|
|
152
146
|
"OUTFILE",
|
|
153
|
-
"PARTITION",
|
|
154
147
|
"PRECISION",
|
|
155
148
|
"PRIMARY",
|
|
156
149
|
"PROCEDURE",
|
|
@@ -167,14 +160,11 @@ reserved_words = [
|
|
|
167
160
|
"REPEAT",
|
|
168
161
|
"REPLACE",
|
|
169
162
|
"REQUIRE",
|
|
170
|
-
"RESIGNAL",
|
|
171
163
|
"RESTRICT",
|
|
172
164
|
"RETURN",
|
|
173
165
|
"REVOKE",
|
|
174
166
|
"RIGHT",
|
|
175
167
|
"RLIKE",
|
|
176
|
-
"ROW",
|
|
177
|
-
"ROWS",
|
|
178
168
|
"SCHEMA",
|
|
179
169
|
"SCHEMAS",
|
|
180
170
|
"SECOND_MICROSECOND",
|
|
@@ -183,7 +173,6 @@ reserved_words = [
|
|
|
183
173
|
"SEPARATOR",
|
|
184
174
|
"SET",
|
|
185
175
|
"SHOW",
|
|
186
|
-
"SIGNAL",
|
|
187
176
|
"SMALLINT",
|
|
188
177
|
"SPATIAL",
|
|
189
178
|
"SPECIFIC",
|
|
@@ -196,7 +185,6 @@ reserved_words = [
|
|
|
196
185
|
"SQL_SMALL_RESULT",
|
|
197
186
|
"SSL",
|
|
198
187
|
"STARTING",
|
|
199
|
-
"STORED",
|
|
200
188
|
"STRAIGHT_JOIN",
|
|
201
189
|
"TABLE",
|
|
202
190
|
"TERMINATED",
|
|
@@ -225,13 +213,13 @@ reserved_words = [
|
|
|
225
213
|
"VARCHAR",
|
|
226
214
|
"VARCHARACTER",
|
|
227
215
|
"VARYING",
|
|
228
|
-
"VIRTUAL",
|
|
229
216
|
"WHEN",
|
|
230
217
|
"WHERE",
|
|
231
218
|
"WHILE",
|
|
232
219
|
"WITH",
|
|
233
220
|
"WRITE",
|
|
221
|
+
"X509",
|
|
234
222
|
"XOR",
|
|
235
223
|
"YEAR_MONTH",
|
|
236
|
-
"ZEROFILL"
|
|
224
|
+
"ZEROFILL"
|
|
237
225
|
]
|