Skip to content

Commit 7ee77d2

Browse files
committed
add new sqlalchemy examples
1 parent ba6206d commit 7ee77d2

File tree

124 files changed

+2270
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+2270
-115
lines changed

content/pages/examples/sqlalchemy/sqlalchemy-exc-argumenterror.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the ArgumentError class from the
1616
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1717
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
1818
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from graphene-sqlalchemy

content/pages/examples/sqlalchemy/sqlalchemy-exc-databaseerror.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the DatabaseError class from the
1616
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1717
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
1818
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from indico

content/pages/examples/sqlalchemy/sqlalchemy-exc-dataerror.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the DataError class from the sql
1616
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1717
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
1818
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from sqlalchemy-utils

content/pages/examples/sqlalchemy/sqlalchemy-exc-integrityerror.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the IntegrityError class from th
1616
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1717
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
1818
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from CTFd

content/pages/examples/sqlalchemy/sqlalchemy-exc-invalidrequesterror.markdown

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the InvalidRequestError class fr
1616
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1717
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
1818
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from GINO
@@ -124,3 +125,141 @@ class ColumnAttribute:
124125

125126
```
126127

128+
129+
## Example 2 from SQLAlchemy filters
130+
[SQLAlchemy filters](https://github.com/juliotrigo/sqlalchemy-filters)
131+
provides filtering, sorting and pagination for [SQLAlchemy](/sqlalchemy.html)
132+
query objects, which is particularly useful when building
133+
[web APIs](/application-programming-interfaces.html). SQLAlchemy filters
134+
is open sourced under the
135+
[Apache License version 2.0](https://github.com/juliotrigo/sqlalchemy-filters/blob/master/LICENSE).
136+
137+
[**SQLAlchemy filters / sqlalchemy_filters / models.py**](https://github.com/juliotrigo/sqlalchemy-filters/blob/master/sqlalchemy_filters/./models.py)
138+
139+
```python
140+
# models.py
141+
~~from sqlalchemy.exc import InvalidRequestError
142+
from sqlalchemy.inspection import inspect
143+
from sqlalchemy.orm.mapper import Mapper
144+
from sqlalchemy.util import symbol
145+
import types
146+
147+
from .exceptions import BadQuery, FieldNotFound, BadSpec
148+
149+
150+
class Field(object):
151+
152+
def __init__(self, model, field_name):
153+
self.model = model
154+
self.field_name = field_name
155+
156+
def get_sqlalchemy_field(self):
157+
if self.field_name not in self._get_valid_field_names():
158+
raise FieldNotFound(
159+
'Model {} has no column `{}`.'.format(
160+
self.model, self.field_name
161+
)
162+
)
163+
sqlalchemy_field = getattr(self.model, self.field_name)
164+
165+
if isinstance(sqlalchemy_field, types.MethodType):
166+
167+
168+
## ... source file abbreviated to get to InvalidRequestError examples ...
169+
170+
171+
172+
def get_model_class_by_name(registry, name):
173+
for cls in registry.values():
174+
if getattr(cls, '__name__', None) == name:
175+
return cls
176+
177+
178+
def get_default_model(query):
179+
query_models = get_query_models(query).values()
180+
if len(query_models) == 1:
181+
default_model, = iter(query_models)
182+
else:
183+
default_model = None
184+
return default_model
185+
186+
187+
def auto_join(query, *model_names):
188+
query_models = get_query_models(query).values()
189+
model_registry = list(query_models)[-1]._decl_class_registry
190+
191+
for name in model_names:
192+
model = get_model_class_by_name(model_registry, name)
193+
if model not in get_query_models(query).values():
194+
try:
195+
query = query.join(model)
196+
~~ except InvalidRequestError:
197+
pass # can't be autojoined
198+
return query
199+
200+
201+
202+
## ... source file continues with no further InvalidRequestError examples...
203+
204+
```
205+
206+
207+
## Example 3 from SQLAthanor
208+
[SQLAthanor](https://github.com/insightindustry/sqlathanor)
209+
([PyPI package information](https://pypi.org/project/sqlathanor/)
210+
and
211+
[project documentation](https://sqlathanor.readthedocs.io/en/latest/index.html))
212+
is a [SQLAlchemy](/sqlalchemy.html) extension that provides serialization and
213+
deserialization support for JSON, CSV, YAML and Python dictionaries.
214+
This project is similar to [Marshmallow](https://marshmallow.readthedocs.io/en/stable/)
215+
with one major difference: SQLAthanor works through SQLAlchemy models
216+
while Marshmallow is less coupled to SQLAlchemy because it requires
217+
separate representations of the serialization objects. Both libraries
218+
have their uses depending on whether the project plans to use SQLAlchemy
219+
for object representations or would prefer to avoid that couping.
220+
SQLAthanor is open sourced under the
221+
[MIT license](https://github.com/insightindustry/sqlathanor/blob/master/LICENSE).
222+
223+
[**SQLAthanor / sqlathanor / utilities.py**](https://github.com/insightindustry/sqlathanor/blob/master/sqlathanor/./utilities.py)
224+
225+
```python
226+
# utilities.py
227+
228+
import csv
229+
import linecache
230+
import warnings
231+
import yaml
232+
from collections import OrderedDict
233+
234+
from sqlalchemy.orm.collections import InstrumentedList
235+
~~from sqlalchemy.exc import InvalidRequestError as SA_InvalidRequestError
236+
from sqlalchemy.exc import UnsupportedCompilationError as SA_UnsupportedCompilationError
237+
238+
from validator_collection import validators, checkers
239+
from validator_collection.errors import NotAnIterableError
240+
241+
from sqlathanor._compat import json, is_py2, is_py36, is_py35, dict as dict_
242+
from sqlathanor.errors import InvalidFormatError, UnsupportedSerializationError, \
243+
UnsupportedDeserializationError, MaximumNestingExceededError, \
244+
MaximumNestingExceededWarning, DeserializationError, CSVStructureError
245+
246+
UTILITY_COLUMNS = [
247+
'metadata',
248+
'primary_key_value',
249+
'_decl_class_registry',
250+
'_sa_instance_state',
251+
'_sa_class_manager'
252+
]
253+
254+
def bool_to_tuple(input):
255+
256+
if input is True:
257+
input = (True, True)
258+
elif not input:
259+
input = (False, False)
260+
261+
262+
## ... source file continues with no further InvalidRequestError examples...
263+
264+
```
265+

content/pages/examples/sqlalchemy/sqlalchemy-exc-noinspectionavailable.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the NoInspectionAvailable class
1616
<a href="/sqlalchemy-exc-invalidrequesterror-examples.html">InvalidRequestError</a>,
1717
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
1818
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from sqlalchemy-utils

content/pages/examples/sqlalchemy/sqlalchemy-exc-nosuchtableerror.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the NoSuchTableError class from
1616
<a href="/sqlalchemy-exc-invalidrequesterror-examples.html">InvalidRequestError</a>,
1717
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1818
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from PyHive

content/pages/examples/sqlalchemy/sqlalchemy-exc-operationalerror.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the OperationalError class from
1616
<a href="/sqlalchemy-exc-invalidrequesterror-examples.html">InvalidRequestError</a>,
1717
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1818
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
19-
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
19+
<a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from indico

content/pages/examples/sqlalchemy/sqlalchemy-exc-programmingerror.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ meta: Example code for understanding how to use the ProgrammingError class from
1616
<a href="/sqlalchemy-exc-invalidrequesterror-examples.html">InvalidRequestError</a>,
1717
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
1818
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
19-
and <a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>
19+
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
20+
and <a href="/sqlalchemy-exc-unsupportedcompilationerror-examples.html">UnsupportedCompilationError</a>
2021
are several other callables with code examples from the same `sqlalchemy.exc` package.
2122

2223
## Example 1 from sqlalchemy-utils
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
title: sqlalchemy.exc UnsupportedCompilationError Example Code
2+
category: page
3+
slug: sqlalchemy-exc-unsupportedcompilationerror-examples
4+
sortorder: 500031043
5+
toc: False
6+
sidebartitle: sqlalchemy.exc UnsupportedCompilationError
7+
meta: Example code for understanding how to use the UnsupportedCompilationError class from the sqlalchemy.exc module of the SQLAlchemy project.
8+
9+
10+
`UnsupportedCompilationError` is a class within the `sqlalchemy.exc` module of the SQLAlchemy project.
11+
12+
<a href="/sqlalchemy-exc-argumenterror-examples.html">ArgumentError</a>,
13+
<a href="/sqlalchemy-exc-dataerror-examples.html">DataError</a>,
14+
<a href="/sqlalchemy-exc-databaseerror-examples.html">DatabaseError</a>,
15+
<a href="/sqlalchemy-exc-integrityerror-examples.html">IntegrityError</a>,
16+
<a href="/sqlalchemy-exc-invalidrequesterror-examples.html">InvalidRequestError</a>,
17+
<a href="/sqlalchemy-exc-noinspectionavailable-examples.html">NoInspectionAvailable</a>,
18+
<a href="/sqlalchemy-exc-nosuchtableerror-examples.html">NoSuchTableError</a>,
19+
<a href="/sqlalchemy-exc-operationalerror-examples.html">OperationalError</a>,
20+
and <a href="/sqlalchemy-exc-programmingerror-examples.html">ProgrammingError</a>
21+
are several other callables with code examples from the same `sqlalchemy.exc` package.
22+
23+
## Example 1 from SQLAthanor
24+
[SQLAthanor](https://github.com/insightindustry/sqlathanor)
25+
([PyPI package information](https://pypi.org/project/sqlathanor/)
26+
and
27+
[project documentation](https://sqlathanor.readthedocs.io/en/latest/index.html))
28+
is a [SQLAlchemy](/sqlalchemy.html) extension that provides serialization and
29+
deserialization support for JSON, CSV, YAML and Python dictionaries.
30+
This project is similar to [Marshmallow](https://marshmallow.readthedocs.io/en/stable/)
31+
with one major difference: SQLAthanor works through SQLAlchemy models
32+
while Marshmallow is less coupled to SQLAlchemy because it requires
33+
separate representations of the serialization objects. Both libraries
34+
have their uses depending on whether the project plans to use SQLAlchemy
35+
for object representations or would prefer to avoid that couping.
36+
SQLAthanor is open sourced under the
37+
[MIT license](https://github.com/insightindustry/sqlathanor/blob/master/LICENSE).
38+
39+
[**SQLAthanor / sqlathanor / utilities.py**](https://github.com/insightindustry/sqlathanor/blob/master/sqlathanor/./utilities.py)
40+
41+
```python
42+
# utilities.py
43+
44+
import csv
45+
import linecache
46+
import warnings
47+
import yaml
48+
from collections import OrderedDict
49+
50+
from sqlalchemy.orm.collections import InstrumentedList
51+
from sqlalchemy.exc import InvalidRequestError as SA_InvalidRequestError
52+
~~from sqlalchemy.exc import UnsupportedCompilationError as SA_UnsupportedCompilationError
53+
54+
from validator_collection import validators, checkers
55+
from validator_collection.errors import NotAnIterableError
56+
57+
from sqlathanor._compat import json, is_py2, is_py36, is_py35, dict as dict_
58+
from sqlathanor.errors import InvalidFormatError, UnsupportedSerializationError, \
59+
UnsupportedDeserializationError, MaximumNestingExceededError, \
60+
MaximumNestingExceededWarning, DeserializationError, CSVStructureError
61+
62+
UTILITY_COLUMNS = [
63+
'metadata',
64+
'primary_key_value',
65+
'_decl_class_registry',
66+
'_sa_instance_state',
67+
'_sa_class_manager'
68+
]
69+
70+
def bool_to_tuple(input):
71+
72+
if input is True:
73+
input = (True, True)
74+
elif not input:
75+
input = (False, False)
76+
elif not isinstance(input, tuple) or len(input) > 2:
77+
78+
79+
## ... source file continues with no further UnsupportedCompilationError examples...
80+
81+
```
82+

0 commit comments

Comments
 (0)