File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,14 @@ def _builder(cls, **kwargs: Any) -> "MySQLQueryBuilder":
73
73
def load (cls , fp : str ) -> "MySQLLoadQueryBuilder" :
74
74
return MySQLLoadQueryBuilder ().load (fp )
75
75
76
+ @classmethod
77
+ def create_table (cls , table : Union [str , Table ]) -> "MySQLCreateQueryBuilder" :
78
+ return MySQLCreateQueryBuilder ().create_table (table )
79
+
80
+ @classmethod
81
+ def drop_table (cls , table : Union [str , Table ]) -> "MySQLDropQueryBuilder" :
82
+ return MySQLDropQueryBuilder ().drop_table (table )
83
+
76
84
77
85
class MySQLQueryBuilder (QueryBuilder ):
78
86
QUOTE_CHAR = "`"
@@ -212,6 +220,14 @@ def __str__(self) -> str:
212
220
return self .get_sql ()
213
221
214
222
223
+ class MySQLCreateQueryBuilder (CreateQueryBuilder ):
224
+ QUOTE_CHAR = "`"
225
+
226
+
227
+ class MySQLDropQueryBuilder (DropQueryBuilder ):
228
+ QUOTE_CHAR = "`"
229
+
230
+
215
231
class VerticaQuery (Query ):
216
232
"""
217
233
Defines a query class for use with Vertica.
Original file line number Diff line number Diff line change 1
1
import unittest
2
2
3
- from pypika import MySQLQuery , QueryException , Table
3
+ from pypika import MySQLQuery , QueryException , Table , Column
4
4
5
5
6
6
class SelectTests (unittest .TestCase ):
@@ -71,3 +71,21 @@ def test_load_from_file(self):
71
71
"LOAD DATA LOCAL INFILE '/path/to/file' INTO TABLE `abc` FIELDS TERMINATED BY ','" ,
72
72
str (q2 ),
73
73
)
74
+
75
+
76
+ class TableTests (unittest .TestCase ):
77
+ table_abc = Table ("abc" )
78
+
79
+ def test_create_table (self ):
80
+ q = MySQLQuery .create_table (self .table_abc ).columns (Column ("id" , "INT" ))
81
+ self .assertEqual (
82
+ 'CREATE TABLE `abc` (`id` INT)' ,
83
+ str (q ),
84
+ )
85
+
86
+ def test_drop_table (self ):
87
+ q = MySQLQuery .drop_table (self .table_abc )
88
+ self .assertEqual (
89
+ 'DROP TABLE `abc`' ,
90
+ str (q ),
91
+ )
You can’t perform that action at this time.
0 commit comments