DefPixel-PostgreSQL 0.1.6__91-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.
Files changed (68) hide show
  1. DefPixel/DataAccessObject/Implements/PostgreSQL/Adapters/Array.py +16 -0
  2. DefPixel/DataAccessObject/Implements/PostgreSQL/Adapters/JavaScriptObjectNotation.py +74 -0
  3. DefPixel/DataAccessObject/Implements/PostgreSQL/Adapters/__init__.py +51 -0
  4. DefPixel/DataAccessObject/Implements/PostgreSQL/Column.py +34 -0
  5. DefPixel/DataAccessObject/Implements/PostgreSQL/Compiler.py +161 -0
  6. DefPixel/DataAccessObject/Implements/PostgreSQL/Configuration.py +116 -0
  7. DefPixel/DataAccessObject/Implements/PostgreSQL/Connection.py +138 -0
  8. DefPixel/DataAccessObject/Implements/PostgreSQL/Constraint.py +18 -0
  9. DefPixel/DataAccessObject/Implements/PostgreSQL/Constraints/Check.py +23 -0
  10. DefPixel/DataAccessObject/Implements/PostgreSQL/Constraints/Columns.py +24 -0
  11. DefPixel/DataAccessObject/Implements/PostgreSQL/Constraints/ForeignKey.py +56 -0
  12. DefPixel/DataAccessObject/Implements/PostgreSQL/Constraints/PrimaryKey.py +21 -0
  13. DefPixel/DataAccessObject/Implements/PostgreSQL/Constraints/Unique.py +25 -0
  14. DefPixel/DataAccessObject/Implements/PostgreSQL/Constraints/__init__.py +13 -0
  15. DefPixel/DataAccessObject/Implements/PostgreSQL/Context.py +48 -0
  16. DefPixel/DataAccessObject/Implements/PostgreSQL/Cursor.py +123 -0
  17. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Create.py +181 -0
  18. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Delete.py +31 -0
  19. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Drop.py +53 -0
  20. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Get.py +24 -0
  21. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Insert.py +98 -0
  22. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Query.py +37 -0
  23. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Select.py +122 -0
  24. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/Update.py +57 -0
  25. DefPixel/DataAccessObject/Implements/PostgreSQL/Executors/__init__.py +19 -0
  26. DefPixel/DataAccessObject/Implements/PostgreSQL/Expr.py +11 -0
  27. DefPixel/DataAccessObject/Implements/PostgreSQL/Exprs/Common.py +180 -0
  28. DefPixel/DataAccessObject/Implements/PostgreSQL/Exprs/Compare.py +87 -0
  29. DefPixel/DataAccessObject/Implements/PostgreSQL/Exprs/Condition.py +155 -0
  30. DefPixel/DataAccessObject/Implements/PostgreSQL/Exprs/JavaScriptObjectNotation.py +53 -0
  31. DefPixel/DataAccessObject/Implements/PostgreSQL/Exprs/Operator.py +42 -0
  32. DefPixel/DataAccessObject/Implements/PostgreSQL/Exprs/String.py +48 -0
  33. DefPixel/DataAccessObject/Implements/PostgreSQL/Exprs/__init__.py +75 -0
  34. DefPixel/DataAccessObject/Implements/PostgreSQL/Function.py +11 -0
  35. DefPixel/DataAccessObject/Implements/PostgreSQL/Functions/Common.py +142 -0
  36. DefPixel/DataAccessObject/Implements/PostgreSQL/Functions/DateTime.py +219 -0
  37. DefPixel/DataAccessObject/Implements/PostgreSQL/Functions/JavaScriptObjectNotation.py +100 -0
  38. DefPixel/DataAccessObject/Implements/PostgreSQL/Functions/Sequence.py +55 -0
  39. DefPixel/DataAccessObject/Implements/PostgreSQL/Functions/__init__.py +91 -0
  40. DefPixel/DataAccessObject/Implements/PostgreSQL/Index.py +135 -0
  41. DefPixel/DataAccessObject/Implements/PostgreSQL/Joins/FullOuter.py +15 -0
  42. DefPixel/DataAccessObject/Implements/PostgreSQL/Joins/Inner.py +15 -0
  43. DefPixel/DataAccessObject/Implements/PostgreSQL/Joins/Join.py +41 -0
  44. DefPixel/DataAccessObject/Implements/PostgreSQL/Joins/LeftOuter.py +15 -0
  45. DefPixel/DataAccessObject/Implements/PostgreSQL/Joins/RightOuter.py +15 -0
  46. DefPixel/DataAccessObject/Implements/PostgreSQL/Joins/__init__.py +15 -0
  47. DefPixel/DataAccessObject/Implements/PostgreSQL/Mapping.py +359 -0
  48. DefPixel/DataAccessObject/Implements/PostgreSQL/Orders.py +59 -0
  49. DefPixel/DataAccessObject/Implements/PostgreSQL/Pool.py +84 -0
  50. DefPixel/DataAccessObject/Implements/PostgreSQL/Schema.py +28 -0
  51. DefPixel/DataAccessObject/Implements/PostgreSQL/Sequence.py +55 -0
  52. DefPixel/DataAccessObject/Implements/PostgreSQL/Session.py +84 -0
  53. DefPixel/DataAccessObject/Implements/PostgreSQL/Type.py +113 -0
  54. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/Array.py +61 -0
  55. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/Binary.py +34 -0
  56. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/Bool.py +29 -0
  57. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/DateTime.py +120 -0
  58. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/JavaScriptObjectNotation.py +52 -0
  59. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/Numeric.py +151 -0
  60. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/Size.py +13 -0
  61. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/String.py +80 -0
  62. DefPixel/DataAccessObject/Implements/PostgreSQL/Types/__init__.py +76 -0
  63. DefPixel/DataAccessObject/Implements/PostgreSQL/__init__.py +85 -0
  64. defpixel_postgresql-0.1.6.dist-info/METADATA +184 -0
  65. defpixel_postgresql-0.1.6.dist-info/RECORD +68 -0
  66. defpixel_postgresql-0.1.6.dist-info/WHEEL +6 -0
  67. defpixel_postgresql-0.1.6.dist-info/licenses/LICENSE +674 -0
  68. defpixel_postgresql-0.1.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Compiler import (
4
+ Compiler,
5
+ quote,
6
+ )
7
+ from ..Function import Function
8
+ from ..Schema import Schema
9
+ from ..Sequence import Sequence
10
+
11
+ __all__ = (
12
+ 'NextVal',
13
+ 'CurrVal',
14
+ )
15
+
16
+
17
+ class SequenceFunction(Function):
18
+ name = ''
19
+
20
+ def __init__(
21
+ self,
22
+ sequence,
23
+ schema=None,
24
+ ):
25
+ if not isinstance(sequence, (Sequence, str)):
26
+ raise TypeError('sequence must be a Sequence or a sequence name')
27
+ if isinstance(schema, Schema):
28
+ schema = schema.name
29
+ if schema is not None and not isinstance(schema, str):
30
+ raise TypeError('schema must be a Schema or a schema name')
31
+ quote(str(sequence))
32
+ if schema is not None:
33
+ quote(schema)
34
+ self.sequence = sequence
35
+ self.schema = schema
36
+ return
37
+
38
+ def compile(self, compiler: Compiler) -> str:
39
+ schema = self.schema
40
+ if schema is None and isinstance(self.sequence, Sequence):
41
+ schema = self.sequence.schema
42
+ name = quote(str(self.sequence))
43
+ if schema is not None:
44
+ name = '{}.{}'.format(quote(schema), name)
45
+ return '{}({})'.format(self.name, compiler.bind(name, 'REGCLASS'))
46
+
47
+
48
+ class NextVal(SequenceFunction):
49
+ """NEXTVAL of a sequence; a Sequence declared on a table uses the table schema by default."""
50
+ name = 'NEXTVAL'
51
+
52
+
53
+ class CurrVal(SequenceFunction):
54
+ """CURRVAL of a sequence in the current session."""
55
+ name = 'CURRVAL'
@@ -0,0 +1,91 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Common import (
4
+ Count,
5
+ Sum,
6
+ Average,
7
+ Min,
8
+ Max,
9
+ AggregateToArray,
10
+ RowNumber,
11
+ Rank,
12
+ DenseRank,
13
+ )
14
+ from .DateTime import (
15
+ Now,
16
+ DatePartType,
17
+ DatePart,
18
+ Year,
19
+ Month,
20
+ Day,
21
+ Hour,
22
+ Minute,
23
+ Second,
24
+ MilliSecond,
25
+ MicroSecond,
26
+ Quarter,
27
+ Week,
28
+ DayOfWeek,
29
+ DayOfWeekISO,
30
+ DayOfYear,
31
+ Timezone,
32
+ TimezoneHour,
33
+ TimezoneMinute,
34
+ TimezoneHourMinute,
35
+ Millennium,
36
+ Century,
37
+ Decade,
38
+ Epoch,
39
+ )
40
+ from .Sequence import (
41
+ NextVal,
42
+ CurrVal,
43
+ )
44
+ from .JavaScriptObjectNotation import (
45
+ AggregateToJSON,
46
+ AggregateToJSONB,
47
+ ToJSON,
48
+ ToJSONB,
49
+ )
50
+
51
+ __all__ = (
52
+ 'Count',
53
+ 'Sum',
54
+ 'Average',
55
+ 'Min',
56
+ 'Max',
57
+ 'AggregateToArray',
58
+ 'RowNumber',
59
+ 'Rank',
60
+ 'DenseRank',
61
+ 'Now',
62
+ 'DatePartType',
63
+ 'DatePart',
64
+ 'Year',
65
+ 'Month',
66
+ 'Day',
67
+ 'Hour',
68
+ 'Minute',
69
+ 'Second',
70
+ 'MilliSecond',
71
+ 'MicroSecond',
72
+ 'Quarter',
73
+ 'Week',
74
+ 'DayOfWeek',
75
+ 'DayOfWeekISO',
76
+ 'DayOfYear',
77
+ 'Timezone',
78
+ 'TimezoneHour',
79
+ 'TimezoneMinute',
80
+ 'TimezoneHourMinute',
81
+ 'Millennium',
82
+ 'Century',
83
+ 'Decade',
84
+ 'Epoch',
85
+ 'NextVal',
86
+ 'CurrVal',
87
+ 'AggregateToJSON',
88
+ 'AggregateToJSONB',
89
+ 'ToJSON',
90
+ 'ToJSONB',
91
+ )
@@ -0,0 +1,135 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from collections.abc import Sequence
4
+ from enum import Enum
5
+ from re import fullmatch
6
+ from typing import Optional
7
+
8
+ from .Column import Column
9
+ from .Compiler import (
10
+ Compilable,
11
+ Compiler,
12
+ identifier,
13
+ )
14
+ from .Expr import Expr
15
+ from .Type import Type
16
+
17
+ __all__ = (
18
+ 'IndexType',
19
+ 'Index',
20
+ 'IndexUnique',
21
+ 'IndexOperation',
22
+ )
23
+
24
+
25
+ class IndexType(str, Enum):
26
+ BTree = 'BTREE'
27
+ Hash = 'HASH'
28
+ GeneralizedSearchTree = 'GIST'
29
+ SpacePartitionedGeneralizedSearchTree = 'SPGIST'
30
+ GeneralizedInvertedIndex = 'GIN'
31
+ BlockRangeIndex = 'BRIN'
32
+ Bloom = 'BLOOM'
33
+ ReverseUnorderedMatching = 'RUM'
34
+
35
+ def __str__(self) -> str:
36
+ return self.value
37
+
38
+
39
+ EXTENSIONS = {
40
+ IndexType.Bloom: 'bloom',
41
+ IndexType.ReverseUnorderedMatching: 'rum',
42
+ }
43
+
44
+
45
+ def expression(value):
46
+ if isinstance(value, str):
47
+ identifier(value)
48
+ return value
49
+ if not isinstance(value, Compilable):
50
+ raise TypeError('Index expressions must be column names or SQL expressions')
51
+ return value
52
+
53
+
54
+ class Index:
55
+ """Index declaration with optional access method and partial-index condition."""
56
+
57
+ def __init__(
58
+ self,
59
+ name: str,
60
+ exprs,
61
+ unique: bool = False,
62
+ using: Optional[IndexType] = None,
63
+ notexists: bool = True,
64
+ ):
65
+ identifier(name)
66
+ if isinstance(exprs, Sequence) and not isinstance(exprs, str):
67
+ exprs = list(exprs)
68
+ else:
69
+ exprs = [exprs]
70
+ if not exprs:
71
+ raise ValueError('An index requires at least one expression')
72
+ if using is not None:
73
+ using = IndexType(using)
74
+ self.name = name
75
+ self.exprs = [expression(expr) for expr in exprs]
76
+ self.unique = bool(unique)
77
+ self.using = using
78
+ self.notexists = bool(notexists)
79
+ self.conds = ()
80
+ return
81
+
82
+ def where(self, *args) -> 'Index':
83
+ for arg in args:
84
+ if not isinstance(arg, Compilable):
85
+ raise TypeError('Index conditions must be SQL expressions')
86
+ self.conds = args
87
+ return self
88
+
89
+ @property
90
+ def extension(self) -> Optional[str]:
91
+ return EXTENSIONS.get(self.using)
92
+
93
+
94
+ class IndexUnique(Index):
95
+ """Unique index declaration."""
96
+
97
+ def __init__(
98
+ self,
99
+ name: str,
100
+ exprs,
101
+ using: Optional[IndexType] = None,
102
+ notexists: bool = True,
103
+ ):
104
+ super().__init__(
105
+ name=name,
106
+ exprs=exprs,
107
+ unique=True,
108
+ using=using,
109
+ notexists=notexists,
110
+ )
111
+ return
112
+
113
+
114
+ class IndexOperation(Expr):
115
+ """Index element with an operator class, for example GIN_TRGM_OPS."""
116
+
117
+ def __init__(
118
+ self,
119
+ col,
120
+ operator: str,
121
+ ):
122
+ if not isinstance(operator, str) or not fullmatch(r'[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?', operator):
123
+ raise ValueError('Operator class names must be plain SQL names')
124
+ self.col = Column(col) if isinstance(col, str) else expression(col)
125
+ self.operator = operator
126
+ return
127
+
128
+ def compile(self, compiler: Compiler) -> str:
129
+ col = compiler.compile(self.col)
130
+ if not (
131
+ isinstance(self.col, Column) and self.col.typecast is None
132
+ or isinstance(self.col, Type) and not compiler.qualify
133
+ ):
134
+ col = '({})'.format(col)
135
+ return '{} {}'.format(col, self.operator)
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Join import Join
4
+
5
+ __all__ = (
6
+ 'FullOuter',
7
+ )
8
+
9
+
10
+ class FullOuter(Join):
11
+ """FULL OUTER JOIN."""
12
+
13
+ def __init__(self, table, *args):
14
+ super().__init__('FULL OUTER', table, *args)
15
+ return
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Join import Join
4
+
5
+ __all__ = (
6
+ 'Inner',
7
+ )
8
+
9
+
10
+ class Inner(Join):
11
+ """INNER JOIN."""
12
+
13
+ def __init__(self, table, *args):
14
+ super().__init__('INNER', table, *args)
15
+ return
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Compiler import Compiler
4
+ from ..Expr import Expr
5
+ from ..Exprs.Operator import conditions
6
+ from ..Mapping import inspect_model
7
+
8
+ __all__ = (
9
+ 'Join',
10
+ )
11
+
12
+
13
+ class Join(Expr):
14
+ """JOIN of a mapped table or view with ON conditions."""
15
+
16
+ KINDS = ('INNER', 'LEFT OUTER', 'RIGHT OUTER', 'FULL OUTER')
17
+
18
+ def __init__(self, expr: str, table, *args):
19
+ if expr not in self.KINDS:
20
+ raise ValueError('Join type must be one of: {}'.format(', '.join(self.KINDS)))
21
+ self.expr = expr
22
+ self.mapping = inspect_model(table)
23
+ self.args = list(conditions(args))
24
+ return
25
+
26
+ def on(self, *args):
27
+ self.args = list(conditions(args))
28
+ return self
29
+
30
+ def where(self, expr):
31
+ self.args.extend(conditions((expr,)))
32
+ return self
33
+
34
+ def compile(self, compiler: Compiler) -> str:
35
+ if not self.args:
36
+ raise ValueError('A join requires at least one ON condition')
37
+ return '{} JOIN {} ON {}'.format(
38
+ self.expr,
39
+ self.mapping.target,
40
+ ' AND '.join(compiler.compile(arg) for arg in self.args),
41
+ )
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Join import Join
4
+
5
+ __all__ = (
6
+ 'LeftOuter',
7
+ )
8
+
9
+
10
+ class LeftOuter(Join):
11
+ """LEFT OUTER JOIN."""
12
+
13
+ def __init__(self, table, *args):
14
+ super().__init__('LEFT OUTER', table, *args)
15
+ return
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Join import Join
4
+
5
+ __all__ = (
6
+ 'RightOuter',
7
+ )
8
+
9
+
10
+ class RightOuter(Join):
11
+ """RIGHT OUTER JOIN."""
12
+
13
+ def __init__(self, table, *args):
14
+ super().__init__('RIGHT OUTER', table, *args)
15
+ return
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Join import Join
4
+ from .Inner import Inner
5
+ from .LeftOuter import LeftOuter
6
+ from .RightOuter import RightOuter
7
+ from .FullOuter import FullOuter
8
+
9
+ __all__ = (
10
+ 'Join',
11
+ 'Inner',
12
+ 'LeftOuter',
13
+ 'RightOuter',
14
+ 'FullOuter',
15
+ )