Skip to content

Commit da72ba1

Browse files
committed
lint: double -> single quote
1 parent 42a8d04 commit da72ba1

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.formatting.provider": "black"
3+
}

sqlalchemy_utils/view.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ def __init__(
2323

2424
@compiler.compiles(CreateView)
2525
def compile_create_materialized_view(element, compiler, **kw):
26-
return "CREATE {}{}VIEW {}{} AS {}".format(
27-
"OR REPLACE " if element.or_replace else "",
28-
"MATERIALIZED " if element.materialized else "",
29-
"IF NOT EXISTS " if element.if_not_exists else "",
26+
return 'CREATE {}{}VIEW {}{} AS {}'.format(
27+
'OR REPLACE ' if element.or_replace else '',
28+
'MATERIALIZED ' if element.materialized else '',
29+
'IF NOT EXISTS ' if element.if_not_exists else '',
3030
compiler.dialect.identifier_preparer.quote(element.name),
3131
compiler.sql_compiler.process(element.selectable, literal_binds=True),
3232
)
3333

3434

35-
@compiler.compiles(CreateView, "postgresql")
35+
@compiler.compiles(CreateView, 'postgresql')
3636
def compile_create_materialized_view_(element, compiler, **kw):
37-
"""
37+
'''
3838
CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] [ RECURSIVE ] VIEW name [ ( column_name [, ...] ) ]
3939
[ WITH ( view_option_name [= view_option_value] [, ... ] ) ]
4040
AS query
@@ -50,19 +50,19 @@ def compile_create_materialized_view_(element, compiler, **kw):
5050
5151
see https://www.postgresql.org/docs/current/sql-createview.html
5252
see https://www.postgresql.org/docs/current/sql-creatematerializedview.html
53-
"""
54-
return "CREATE {}{}VIEW {}{} AS {}".format(
55-
"OR REPLACE " if not element.materialized and element.or_replace else "",
56-
"MATERIALIZED " if element.materialized else "",
57-
"IF NOT EXISTS " if element.materialized and element.if_not_exists else "",
53+
'''
54+
return 'CREATE {}{}VIEW {}{} AS {}'.format(
55+
'OR REPLACE ' if not element.materialized and element.or_replace else '',
56+
'MATERIALIZED ' if element.materialized else '',
57+
'IF NOT EXISTS ' if element.materialized and element.if_not_exists else '',
5858
compiler.dialect.identifier_preparer.quote(element.name),
5959
compiler.sql_compiler.process(element.selectable, literal_binds=True),
6060
)
6161

6262

63-
@compiler.compiles(CreateView, "mysql")
63+
@compiler.compiles(CreateView, 'mysql')
6464
def compile_create_materialized_view_(element, compiler, **kw):
65-
"""
65+
'''
6666
CREATE
6767
[OR REPLACE]
6868
[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
@@ -74,19 +74,19 @@ def compile_create_materialized_view_(element, compiler, **kw):
7474
7575
See https://dev.mysql.com/doc/refman/8.0/en/create-view.html
7676
NOTE mysql does not support materialized view
77-
"""
77+
'''
7878
if element.materialized:
79-
raise ValueError("mysql does not support materialized view!")
80-
return "CREATE {}VIEW {} AS {}".format(
81-
"OR REPLACE " if element.or_replace else "",
79+
raise ValueError('mysql does not support materialized view!')
80+
return 'CREATE {}VIEW {} AS {}'.format(
81+
'OR REPLACE ' if element.or_replace else '',
8282
compiler.dialect.identifier_preparer.quote(element.name),
8383
compiler.sql_compiler.process(element.selectable, literal_binds=True),
8484
)
8585

8686

87-
@compiler.compiles(CreateView, "mssql")
87+
@compiler.compiles(CreateView, 'mssql')
8888
def compile_create_materialized_view_(element, compiler, **kw):
89-
"""
89+
'''
9090
CREATE [ OR ALTER ] VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ]
9191
[ WITH <view_attribute> [ ,...n ] ]
9292
AS select_statement
@@ -102,18 +102,18 @@ def compile_create_materialized_view_(element, compiler, **kw):
102102
103103
see https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-ver15
104104
see https://docs.microsoft.com/en-us/sql/t-sql/statements/create-materialized-view-as-select-transact-sql?view=azure-sqldw-latest&viewFallbackFrom=sql-server-ver15
105-
"""
106-
return "CREATE {}{}VIEW {} AS {}".format(
107-
"OR ALTER " if not element.materialized and element.or_replace else "",
108-
"MATERIALIZED " if element.materialized else "",
105+
'''
106+
return 'CREATE {}{}VIEW {} AS {}'.format(
107+
'OR ALTER ' if not element.materialized and element.or_replace else '',
108+
'MATERIALIZED ' if element.materialized else '',
109109
compiler.dialect.identifier_preparer.quote(element.name),
110110
compiler.sql_compiler.process(element.selectable, literal_binds=True),
111111
)
112112

113113

114-
@compiler.compiles(CreateView, "snowflake")
114+
@compiler.compiles(CreateView, 'snowflake')
115115
def compile_create_materialized_view(element, compiler, **kw):
116-
"""
116+
'''
117117
CREATE [ OR REPLACE ] [ SECURE ] [ RECURSIVE ] VIEW [ IF NOT EXISTS ] <name>
118118
[ ( <column_list> ) ]
119119
[ <col1> [ WITH ] MASKING POLICY <policy_name> [ USING ( <col1> , <cond_col1> , ... ) ]
@@ -139,11 +139,11 @@ def compile_create_materialized_view(element, compiler, **kw):
139139
140140
see https://docs.snowflake.com/en/sql-reference/sql/create-view.html
141141
see https://docs.snowflake.com/en/sql-reference/sql/create-materialized-view.html
142-
"""
143-
return "CREATE {}{}VIEW {}{} AS {}".format(
144-
"OR REPLACE " if element.or_replace else "",
145-
"MATERIALIZED " if element.materialized else "",
146-
"IF NOT EXISTS " if element.if_not_exists else "",
142+
'''
143+
return 'CREATE {}{}VIEW {}{} AS {}'.format(
144+
'OR REPLACE ' if element.or_replace else '',
145+
'MATERIALIZED ' if element.materialized else '',
146+
'IF NOT EXISTS ' if element.if_not_exists else '',
147147
compiler.dialect.identifier_preparer.quote(element.name),
148148
compiler.sql_compiler.process(element.selectable, literal_binds=True),
149149
)
@@ -158,10 +158,10 @@ def __init__(self, name, materialized=False, cascade=True):
158158

159159
@compiler.compiles(DropView)
160160
def compile_drop_materialized_view(element, compiler, **kw):
161-
return "DROP {}VIEW IF EXISTS {} {}".format(
162-
"MATERIALIZED " if element.materialized else "",
161+
return 'DROP {}VIEW IF EXISTS {} {}'.format(
162+
'MATERIALIZED ' if element.materialized else '',
163163
compiler.dialect.identifier_preparer.quote(element.name),
164-
"CASCADE" if element.cascade else "",
164+
'CASCADE' if element.cascade else '',
165165
)
166166

167167

@@ -198,7 +198,7 @@ def create_materialized_view(
198198
if_not_exists=False,
199199
or_replace=False,
200200
):
201-
"""Create a view on a given metadata
201+
'''Create a view on a given metadata
202202
203203
:param name: The name of the view to create.
204204
:param selectable: An SQLAlchemy selectable e.g. a select() statement.
@@ -219,7 +219,7 @@ def create_materialized_view(
219219
Same as for ``create_view`` except that a ``CREATE MATERIALIZED VIEW``
220220
statement is emitted instead of a ``CREATE VIEW``.
221221
222-
"""
222+
'''
223223
table = create_table_from_selectable(
224224
name=name,
225225
selectable=selectable,
@@ -230,7 +230,7 @@ def create_materialized_view(
230230

231231
sa.event.listen(
232232
metadata,
233-
"after_create",
233+
'after_create',
234234
CreateView(
235235
name,
236236
selectable,
@@ -240,12 +240,12 @@ def create_materialized_view(
240240
),
241241
)
242242

243-
@sa.event.listens_for(metadata, "after_create")
243+
@sa.event.listens_for(metadata, 'after_create')
244244
def create_indexes(target, connection, **kw):
245245
for idx in table.indexes:
246246
idx.create(connection)
247247

248-
sa.event.listen(metadata, "before_drop", DropView(name, materialized=True))
248+
sa.event.listen(metadata, 'before_drop', DropView(name, materialized=True))
249249
return table
250250

251251

@@ -257,7 +257,7 @@ def create_view(
257257
if_not_exists=False,
258258
or_replace=False,
259259
):
260-
"""Create a view on a given metadata
260+
'''Create a view on a given metadata
261261
262262
:param name: The name of the view to create.
263263
:param selectable: An SQLAlchemy selectable e.g. a select() statement.
@@ -292,43 +292,43 @@ def create_view(
292292
293293
metadata.create_all(engine) # View is created at this point
294294
295-
"""
295+
'''
296296
table = create_table_from_selectable(
297297
name=name, selectable=selectable, metadata=None
298298
)
299299

300300
sa.event.listen(
301301
metadata,
302-
"after_create",
302+
'after_create',
303303
CreateView(
304304
name, selectable, if_not_exists=if_not_exists, or_replace=or_replace
305305
),
306306
)
307307

308-
@sa.event.listens_for(metadata, "after_create")
308+
@sa.event.listens_for(metadata, 'after_create')
309309
def create_indexes(target, connection, **kw):
310310
for idx in table.indexes:
311311
idx.create(connection)
312312

313-
sa.event.listen(metadata, "before_drop", DropView(name, cascade=cascade_on_drop))
313+
sa.event.listen(metadata, 'before_drop', DropView(name, cascade=cascade_on_drop))
314314
return table
315315

316316

317317
def refresh_materialized_view(session, name, concurrently=False):
318-
"""Refreshes an already existing materialized view
318+
'''Refreshes an already existing materialized view
319319
320320
:param session: An SQLAlchemy Session instance.
321321
:param name: The name of the materialized view to refresh.
322322
:param concurrently:
323323
Optional flag that causes the ``CONCURRENTLY`` parameter
324324
to be specified when the materialized view is refreshed.
325-
"""
325+
'''
326326
# Since session.execute() bypasses autoflush, we must manually flush in
327327
# order to include newly-created/modified objects in the refresh.
328328
session.flush()
329329
session.execute(
330-
"REFRESH MATERIALIZED VIEW {}{}".format(
331-
"CONCURRENTLY " if concurrently else "",
330+
'REFRESH MATERIALIZED VIEW {}{}'.format(
331+
'CONCURRENTLY ' if concurrently else '',
332332
session.bind.engine.dialect.identifier_preparer.quote(name),
333333
)
334334
)

0 commit comments

Comments
 (0)