DefPixel 0.1.0__3-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 (92) hide show
  1. DefPixel/DataAccessObject/Configuration.py +15 -0
  2. DefPixel/DataAccessObject/Connection.py +25 -0
  3. DefPixel/DataAccessObject/Implements/Sqlite/Configuration.py +16 -0
  4. DefPixel/DataAccessObject/Implements/Sqlite/Connection.py +96 -0
  5. DefPixel/DataAccessObject/Implements/Sqlite/Constraint.py +9 -0
  6. DefPixel/DataAccessObject/Implements/Sqlite/Constraints/ForeignKey.py +16 -0
  7. DefPixel/DataAccessObject/Implements/Sqlite/Constraints/PrimaryKey.py +15 -0
  8. DefPixel/DataAccessObject/Implements/Sqlite/Constraints/Unique.py +25 -0
  9. DefPixel/DataAccessObject/Implements/Sqlite/Constraints/__init__.py +11 -0
  10. DefPixel/DataAccessObject/Implements/Sqlite/Context.py +36 -0
  11. DefPixel/DataAccessObject/Implements/Sqlite/Cursor.py +87 -0
  12. DefPixel/DataAccessObject/Implements/Sqlite/Executors/Create.py +115 -0
  13. DefPixel/DataAccessObject/Implements/Sqlite/Executors/Delete.py +35 -0
  14. DefPixel/DataAccessObject/Implements/Sqlite/Executors/Drop.py +34 -0
  15. DefPixel/DataAccessObject/Implements/Sqlite/Executors/Get.py +24 -0
  16. DefPixel/DataAccessObject/Implements/Sqlite/Executors/Insert.py +59 -0
  17. DefPixel/DataAccessObject/Implements/Sqlite/Executors/Select.py +109 -0
  18. DefPixel/DataAccessObject/Implements/Sqlite/Executors/Update.py +34 -0
  19. DefPixel/DataAccessObject/Implements/Sqlite/Executors/__init__.py +19 -0
  20. DefPixel/DataAccessObject/Implements/Sqlite/Expr.py +42 -0
  21. DefPixel/DataAccessObject/Implements/Sqlite/Exprs/Alias.py +20 -0
  22. DefPixel/DataAccessObject/Implements/Sqlite/Exprs/Is.py +29 -0
  23. DefPixel/DataAccessObject/Implements/Sqlite/Exprs/__init__.py +13 -0
  24. DefPixel/DataAccessObject/Implements/Sqlite/Filters/Compare.py +149 -0
  25. DefPixel/DataAccessObject/Implements/Sqlite/Filters/Operator.py +26 -0
  26. DefPixel/DataAccessObject/Implements/Sqlite/Filters/String.py +23 -0
  27. DefPixel/DataAccessObject/Implements/Sqlite/Filters/__init__.py +30 -0
  28. DefPixel/DataAccessObject/Implements/Sqlite/Function.py +15 -0
  29. DefPixel/DataAccessObject/Implements/Sqlite/Functions/Common.py +34 -0
  30. DefPixel/DataAccessObject/Implements/Sqlite/Functions/Condition.py +21 -0
  31. DefPixel/DataAccessObject/Implements/Sqlite/Functions/__init__.py +16 -0
  32. DefPixel/DataAccessObject/Implements/Sqlite/Index.py +23 -0
  33. DefPixel/DataAccessObject/Implements/Sqlite/Joins/FullOuter.py +19 -0
  34. DefPixel/DataAccessObject/Implements/Sqlite/Joins/Inner.py +19 -0
  35. DefPixel/DataAccessObject/Implements/Sqlite/Joins/Join.py +31 -0
  36. DefPixel/DataAccessObject/Implements/Sqlite/Joins/LeftOuter.py +19 -0
  37. DefPixel/DataAccessObject/Implements/Sqlite/Joins/RightOuter.py +19 -0
  38. DefPixel/DataAccessObject/Implements/Sqlite/Joins/__init__.py +13 -0
  39. DefPixel/DataAccessObject/Implements/Sqlite/Mapping.py +303 -0
  40. DefPixel/DataAccessObject/Implements/Sqlite/Orders/Ascend.py +24 -0
  41. DefPixel/DataAccessObject/Implements/Sqlite/Orders/Descend.py +24 -0
  42. DefPixel/DataAccessObject/Implements/Sqlite/Orders/__init__.py +9 -0
  43. DefPixel/DataAccessObject/Implements/Sqlite/Session.py +37 -0
  44. DefPixel/DataAccessObject/Implements/Sqlite/Type.py +75 -0
  45. DefPixel/DataAccessObject/Implements/Sqlite/Types/Binary.py +28 -0
  46. DefPixel/DataAccessObject/Implements/Sqlite/Types/DateTime.py +42 -0
  47. DefPixel/DataAccessObject/Implements/Sqlite/Types/Numeric.py +49 -0
  48. DefPixel/DataAccessObject/Implements/Sqlite/Types/String.py +28 -0
  49. DefPixel/DataAccessObject/Implements/Sqlite/Types/__init__.py +34 -0
  50. DefPixel/DataAccessObject/Implements/Sqlite/__init__.py +39 -0
  51. DefPixel/DataAccessObject/Implements/__init__.py +1 -0
  52. DefPixel/DataAccessObject/Properties/Database/Context.py +33 -0
  53. DefPixel/DataAccessObject/Properties/Database/Cursor.py +27 -0
  54. DefPixel/DataAccessObject/Properties/Database/Database.py +48 -0
  55. DefPixel/DataAccessObject/Properties/Database/Executor.py +38 -0
  56. DefPixel/DataAccessObject/Properties/Database/Executors.py +31 -0
  57. DefPixel/DataAccessObject/Properties/Database/Fetch.py +37 -0
  58. DefPixel/DataAccessObject/Properties/Database/Filter.py +21 -0
  59. DefPixel/DataAccessObject/Properties/Database/Run.py +39 -0
  60. DefPixel/DataAccessObject/Properties/Database/Session.py +36 -0
  61. DefPixel/DataAccessObject/Properties/Database/__init__.py +25 -0
  62. DefPixel/DataAccessObject/Properties/Dataclass.py +25 -0
  63. DefPixel/DataAccessObject/Properties/Document/Document.py +36 -0
  64. DefPixel/DataAccessObject/Properties/Document/__init__.py +7 -0
  65. DefPixel/DataAccessObject/Properties/Index/Index.py +48 -0
  66. DefPixel/DataAccessObject/Properties/Index/__init__.py +7 -0
  67. DefPixel/DataAccessObject/Properties/KeyValue/KeyValue.py +44 -0
  68. DefPixel/DataAccessObject/Properties/KeyValue/__init__.py +7 -0
  69. DefPixel/DataAccessObject/Properties/__init__.py +15 -0
  70. DefPixel/DataAccessObject/__init__.py +9 -0
  71. DefPixel/Validator/Pattern.py +36 -0
  72. DefPixel/Validator/Patterns/Array.py +30 -0
  73. DefPixel/Validator/Patterns/Common.py +92 -0
  74. DefPixel/Validator/Patterns/Compare.py +180 -0
  75. DefPixel/Validator/Patterns/Condition.py +60 -0
  76. DefPixel/Validator/Patterns/DataObject.py +85 -0
  77. DefPixel/Validator/Patterns/DateTime.py +111 -0
  78. DefPixel/Validator/Patterns/Number.py +43 -0
  79. DefPixel/Validator/Patterns/Object.py +150 -0
  80. DefPixel/Validator/Patterns/Size.py +110 -0
  81. DefPixel/Validator/Patterns/String.py +85 -0
  82. DefPixel/Validator/Patterns/Type.py +350 -0
  83. DefPixel/Validator/Patterns/__init__.py +137 -0
  84. DefPixel/Validator/Validate.py +29 -0
  85. DefPixel/Validator/Validator.py +30 -0
  86. DefPixel/Validator/__init__.py +11 -0
  87. DefPixel/__init__.py +0 -0
  88. defpixel-0.1.0.dist-info/METADATA +114 -0
  89. defpixel-0.1.0.dist-info/RECORD +92 -0
  90. defpixel-0.1.0.dist-info/WHEEL +6 -0
  91. defpixel-0.1.0.dist-info/licenses/LICENSE +674 -0
  92. defpixel-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,109 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from DefPixel.DataAccessObject.Properties.Database import (
4
+ Executor,
5
+ Fetch,
6
+ )
7
+
8
+ from ..Mapping import (
9
+ identifier,
10
+ inspect_model,
11
+ )
12
+
13
+ __all__ = (
14
+ 'Select',
15
+ )
16
+
17
+
18
+ class Select(Executor, Fetch):
19
+ """Select query for an explicitly mapped dataclass."""
20
+
21
+ def __init__(self, o):
22
+ self.mapping = inspect_model(o)
23
+ self.joins = ()
24
+ self.conds = ()
25
+ self.grps = ()
26
+ self.havs = ()
27
+ self.ords = ()
28
+ self.vals = ()
29
+ self.offset = 0
30
+ self.size = None
31
+ return
32
+
33
+ def join(self, *args):
34
+ self.joins = args
35
+ return self
36
+
37
+ def where(self, *args):
38
+ self.conds = args
39
+ return self
40
+
41
+ def groupBy(self, *args):
42
+ self.grps = args
43
+ return self
44
+
45
+ def having(self, *args):
46
+ self.havs = args
47
+ return self
48
+
49
+ def orderBy(self, *args):
50
+ self.ords = args
51
+ return self
52
+
53
+ def limit(
54
+ self,
55
+ size=None,
56
+ offset=0,
57
+ ):
58
+ if size is not None and (type(size) is not int or size < 0):
59
+ raise ValueError('size must be a nonnegative integer')
60
+ if type(offset) is not int or offset < 0:
61
+ raise ValueError('offset must be a nonnegative integer')
62
+ if size is None and offset:
63
+ raise ValueError('offset requires size')
64
+ self.size = size
65
+ self.offset = offset
66
+ return self
67
+
68
+ def values(self, *args):
69
+ self.vals = args
70
+ return self
71
+
72
+ @property
73
+ def query(self):
74
+ columns = self.vals or tuple(self.mapping.columns.values())
75
+ sql = 'SELECT {} FROM {}'.format(
76
+ ', '.join(str(value) for value in columns),
77
+ identifier(self.mapping.name),
78
+ )
79
+ if self.joins:
80
+ sql += ' ' + ' '.join(str(value) for value in self.joins)
81
+ for keyword, values, separator in (
82
+ ('WHERE', self.conds, ' AND '),
83
+ ('GROUP BY', self.grps, ', '),
84
+ ('HAVING', self.havs, ' AND '),
85
+ ('ORDER BY', self.ords, ', '),
86
+ ):
87
+ if values:
88
+ sql += ' {} {}'.format(keyword, separator.join(str(value) for value in values))
89
+ if self.size is not None:
90
+ sql += ' LIMIT {} OFFSET {}'.format(self.size, self.offset)
91
+ return sql
92
+
93
+ @property
94
+ def args(self):
95
+ return ()
96
+
97
+ def fetch(
98
+ self,
99
+ cursor,
100
+ filter=None,
101
+ fetch=None,
102
+ ):
103
+ mapping = inspect_model(fetch) if fetch is not None else None
104
+ result = []
105
+ for row in cursor.rows():
106
+ if filter is not None:
107
+ row = filter(row)
108
+ result.append(mapping.restore(row) if mapping is not None else row)
109
+ return result if result else None
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Insert import Insert
4
+ from ..Mapping import identifier
5
+
6
+ __all__ = (
7
+ 'Update',
8
+ )
9
+
10
+
11
+ class Update(Insert):
12
+ """Update query preserving set and where chaining."""
13
+
14
+ def __init__(self, o):
15
+ super().__init__(o)
16
+ self.conds = ()
17
+ return
18
+
19
+ def set(self, **kwargs):
20
+ return self.values(**kwargs)
21
+
22
+ def where(self, *args):
23
+ self.conds = args
24
+ return self
25
+
26
+ @property
27
+ def query(self):
28
+ if not self.kwargs:
29
+ raise ValueError('No columns are specified for update')
30
+ return 'UPDATE {} SET {}{} RETURNING *'.format(
31
+ identifier(self.mapping.name),
32
+ ', '.join('{}=?'.format(identifier(key)) for key in self.kwargs),
33
+ ' WHERE ' + ' AND '.join(str(cond) for cond in self.conds) if self.conds else '',
34
+ )
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Create import Create
4
+ from .Drop import Drop
5
+ from .Insert import Insert
6
+ from .Select import Select
7
+ from .Update import Update
8
+ from .Delete import Delete
9
+ from .Get import Get
10
+
11
+ __all__ = (
12
+ 'Create',
13
+ 'Drop',
14
+ 'Insert',
15
+ 'Select',
16
+ 'Update',
17
+ 'Delete',
18
+ 'Get',
19
+ )
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from abc import (
4
+ ABC,
5
+ ABCMeta,
6
+ abstractmethod,
7
+ )
8
+ from datetime import datetime
9
+ from math import isfinite
10
+
11
+ __all__ = (
12
+ 'Expr'
13
+ )
14
+
15
+
16
+ class Expr(ABC, metaclass=ABCMeta):
17
+ """Filter Interface"""
18
+
19
+ def encode(self, o):
20
+ return self.literal(o)
21
+
22
+ @staticmethod
23
+ def literal(value):
24
+ if value is None:
25
+ return 'NULL'
26
+ if isinstance(value, str):
27
+ return "'{}'".format(value.replace("'", "''"))
28
+ if isinstance(value, datetime):
29
+ return Expr.literal(value.isoformat())
30
+ if isinstance(value, bytes):
31
+ return "X'{}'".format(value.hex())
32
+ if isinstance(value, bool):
33
+ return '1' if value else '0'
34
+ if isinstance(value, (int, float)):
35
+ if isinstance(value, float) and not isfinite(value):
36
+ raise ValueError('SQL literals require finite numbers')
37
+ return str(value)
38
+ raise TypeError('Unsupported SQL literal type: {}'.format(type(value).__name__))
39
+
40
+ @abstractmethod
41
+ def __str__(self):
42
+ raise NotImplementedError('{} must be implemented __str__'.format(self.__class__.__name__))
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Expr import Expr
4
+ from ..Type import Type
5
+
6
+ __all__ = (
7
+ 'Alias'
8
+ )
9
+
10
+
11
+ class Alias(Expr):
12
+ def __init__(self, col: Type, name: str):
13
+ self.col = col
14
+ self.name = name
15
+ return
16
+ def __str__(self):
17
+ return '{} AS {}'.format(
18
+ str(self.col),
19
+ self.name,
20
+ )
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Expr import Expr
4
+ from ..Type import Type
5
+
6
+ __all__ = (
7
+ 'IsNull',
8
+ 'IsNotNull',
9
+ )
10
+
11
+
12
+ class IsNull(Expr):
13
+ def __init__(self, col: Type):
14
+ self.col = col
15
+ return
16
+ def __str__(self):
17
+ return '{} IS NULL'.format(
18
+ str(self.col),
19
+ )
20
+
21
+
22
+ class IsNotNull(Expr):
23
+ def __init__(self, col: Type):
24
+ self.col = col
25
+ return
26
+ def __str__(self):
27
+ return '{} IS NOT NULL'.format(
28
+ str(self.col),
29
+ )
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Alias import Alias
4
+ from .Is import (
5
+ IsNull,
6
+ IsNotNull,
7
+ )
8
+
9
+ __all__ = (
10
+ 'Alias',
11
+ 'IsNull',
12
+ 'IsNotNull',
13
+ )
@@ -0,0 +1,149 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Expr import Expr
4
+
5
+ from ..Type import Type
6
+ from ..Function import Function
7
+
8
+ from typing import Union, Any
9
+
10
+ __all__ = (
11
+ 'Equal',
12
+ 'NotEqual',
13
+ 'GreaterThan',
14
+ 'GreaterThanOrEqual',
15
+ 'LessThanOrEqual',
16
+ 'LessThan',
17
+ )
18
+
19
+
20
+ class Equal(Expr):
21
+ """SQL equality expression."""
22
+
23
+ def __init__(
24
+ self,
25
+ col: Union[str, Type, Function],
26
+ other: Union[Any, Type, Function],
27
+ ) -> None:
28
+ self.col = col
29
+ self.other = other
30
+ if isinstance(self.other, Type):
31
+ self.other = str(self.other)
32
+ elif isinstance(self.other, Function):
33
+ self.other = str(self.other)
34
+ else:
35
+ self.other = self.encode(self.other)
36
+ return
37
+
38
+ def __str__(self):
39
+ return '{} = {}'.format(str(self.col), self.other)
40
+
41
+
42
+ class NotEqual(Expr):
43
+ """SQL inequality expression."""
44
+
45
+ def __init__(
46
+ self,
47
+ col: Union[str, Type, Function],
48
+ other: Union[Any, Type, Function],
49
+ ) -> None:
50
+ self.col = col
51
+ self.other = other
52
+ if isinstance(self.other, Type):
53
+ self.other = str(self.other)
54
+ elif isinstance(self.other, Function):
55
+ self.other = str(self.other)
56
+ else:
57
+ self.other = self.encode(self.other)
58
+ return
59
+
60
+ def __str__(self):
61
+ return '{} != {}'.format(str(self.col), self.other)
62
+
63
+
64
+ class GreaterThanOrEqual(Expr):
65
+ """SQL greater-than-or-equal expression."""
66
+
67
+ def __init__(
68
+ self,
69
+ col: Union[str, Type, Function],
70
+ other: Union[Any, Type, Function],
71
+ ) -> None:
72
+ self.col = col
73
+ self.other = other
74
+ if isinstance(self.other, Type):
75
+ self.other = str(self.other)
76
+ elif isinstance(self.other, Function):
77
+ self.other = str(self.other)
78
+ else:
79
+ self.other = self.encode(self.other)
80
+ return
81
+
82
+ def __str__(self):
83
+ return '{} >= {}'.format(str(self.col), self.other)
84
+
85
+
86
+ class GreaterThan(Expr):
87
+ """SQL greater-than expression."""
88
+
89
+ def __init__(
90
+ self,
91
+ col: Union[str, Type, Function],
92
+ other: Union[Any, Type, Function],
93
+ ) -> None:
94
+ self.col = col
95
+ self.other = other
96
+ if isinstance(self.other, Type):
97
+ self.other = str(self.other)
98
+ elif isinstance(self.other, Function):
99
+ self.other = str(self.other)
100
+ else:
101
+ self.other = self.encode(self.other)
102
+ return
103
+
104
+ def __str__(self):
105
+ return '{} > {}'.format(str(self.col), self.other)
106
+
107
+
108
+ class LessThanOrEqual(Expr):
109
+ """SQL less-than-or-equal expression."""
110
+
111
+ def __init__(
112
+ self,
113
+ col: Union[str, Type, Function],
114
+ other: Union[Any, Type, Function],
115
+ ) -> None:
116
+ self.col = col
117
+ self.other = other
118
+ if isinstance(self.other, Type):
119
+ self.other = str(self.other)
120
+ elif isinstance(self.other, Function):
121
+ self.other = str(self.other)
122
+ else:
123
+ self.other = self.encode(self.other)
124
+ return
125
+
126
+ def __str__(self):
127
+ return '{} <= {}'.format(str(self.col), self.other)
128
+
129
+
130
+ class LessThan(Expr):
131
+ """SQL less-than expression."""
132
+
133
+ def __init__(
134
+ self,
135
+ col: Union[str, Type, Function],
136
+ other: Union[Any, Type, Function],
137
+ ) -> None:
138
+ self.col = col
139
+ self.other = other
140
+ if isinstance(self.other, Type):
141
+ self.other = str(self.other)
142
+ elif isinstance(self.other, Function):
143
+ self.other = str(self.other)
144
+ else:
145
+ self.other = self.encode(self.other)
146
+ return
147
+
148
+ def __str__(self):
149
+ return '{} < {}'.format(str(self.col), self.other)
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Expr import Expr
4
+
5
+ __all__ = (
6
+ 'And',
7
+ 'Or',
8
+ )
9
+
10
+
11
+ class And(Expr):
12
+ def __init__(self, *args) -> None:
13
+ self.args = args
14
+ return
15
+
16
+ def __str__(self):
17
+ return ' AND '.join([str(arg) for arg in self.args])
18
+
19
+
20
+ class Or(Expr):
21
+ def __init__(self, *args) -> None:
22
+ self.args = args
23
+ return
24
+
25
+ def __str__(self):
26
+ return ' OR '.join([str(arg) for arg in self.args])
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Expr import Expr
4
+ from ..Type import Type
5
+
6
+ __all__ = (
7
+ 'Like'
8
+ )
9
+
10
+
11
+ class Like(Expr):
12
+ """SQL LIKE expression."""
13
+
14
+ def __init__(self, col: Type, other) -> None:
15
+ self.col = col
16
+ self.other = other
17
+ return
18
+
19
+ def __str__(self):
20
+ return '{} LIKE {}'.format(
21
+ str(self.col),
22
+ self.encode(self.other),
23
+ )
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Operator import (
4
+ And,
5
+ Or,
6
+ )
7
+ from .Compare import (
8
+ Equal,
9
+ NotEqual,
10
+ GreaterThan,
11
+ GreaterThanOrEqual,
12
+ LessThan,
13
+ LessThanOrEqual,
14
+ )
15
+ from .String import (
16
+ Like,
17
+ )
18
+
19
+
20
+ __all__ = (
21
+ 'And',
22
+ 'Or',
23
+ 'Equal',
24
+ 'NotEqual',
25
+ 'Like',
26
+ 'GreaterThan',
27
+ 'GreaterThanOrEqual',
28
+ 'LessThan',
29
+ 'LessThanOrEqual',
30
+ )
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from abc import ABCMeta, abstractmethod
4
+
5
+ __all__ = (
6
+ 'Function'
7
+ )
8
+
9
+
10
+ class Function(metaclass=ABCMeta):
11
+ """Function Interface"""
12
+
13
+ @abstractmethod
14
+ def __str__(self):
15
+ raise NotImplementedError('{} must be implemented __str__'.format(self.__class__.__name__))
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Function import Function
4
+ from ..Type import Type
5
+
6
+ __all__ = (
7
+ 'Count',
8
+ 'Sum',
9
+ 'Average',
10
+ )
11
+
12
+
13
+ class Count(Function):
14
+ def __init__(self, col: Type):
15
+ self.col = col
16
+ return
17
+ def __str__(self):
18
+ return 'COUNT({})'.format(str(self.col))
19
+
20
+
21
+ class Sum(Function):
22
+ def __init__(self, col: Type):
23
+ self.col = col
24
+ return
25
+ def __str__(self):
26
+ return 'SUM({})'.format(str(self.col))
27
+
28
+
29
+ class Average(Function):
30
+ def __init__(self, col: Type):
31
+ self.col = col
32
+ return
33
+ def __str__(self):
34
+ return 'AVG({})'.format(str(self.col))
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Function import Function
4
+ from ..Type import Type
5
+ from ..Expr import Expr
6
+
7
+ __all__ = (
8
+ 'IfNull'
9
+ )
10
+
11
+
12
+ class IfNull(Function):
13
+ def __init__(self, attr: Type, value: any):
14
+ self.attr = attr
15
+ self.value = value
16
+ return
17
+ def __str__(self):
18
+ return 'IFNULL({}, {})'.format(
19
+ str(self.attr),
20
+ self.value if isinstance(self.value, (Type, Function)) else Expr.literal(self.value),
21
+ )
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Common import (
4
+ Sum,
5
+ Count,
6
+ Average,
7
+ )
8
+
9
+ from .Condition import IfNull
10
+
11
+ __all__ = (
12
+ 'Sum',
13
+ 'Count',
14
+ 'Average',
15
+ 'IfNull',
16
+ )
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from typing import Sequence, Union
4
+
5
+ __all__ = (
6
+ 'Index'
7
+ )
8
+
9
+
10
+ class Index(object):
11
+ def __init__(
12
+ self,
13
+ name: str,
14
+ colexprs: Union[str, Sequence[str]],
15
+ expr: str = None,
16
+ notexists: bool = True,
17
+ ):
18
+ self.name = name
19
+ self.colexprs = colexprs if isinstance(colexprs, (tuple, list)) else [colexprs]
20
+ self.expr = expr
21
+ self.notexists = notexists
22
+ return
23
+
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Join import Join
4
+
5
+ from DefPixel.DataAccessObject.Properties import Dataclass
6
+
7
+ from typing import Type
8
+
9
+ __all__ = (
10
+ 'FullOuter'
11
+ )
12
+
13
+
14
+ class FullOuter(Join):
15
+ """Full Outer Join Class"""
16
+
17
+ def __init__(self, table: Type[Dataclass], *args) -> None:
18
+ super(FullOuter, self).__init__('FULL OUTER', table, *args)
19
+ return
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Join import Join
4
+
5
+ from DefPixel.DataAccessObject.Properties import Dataclass
6
+
7
+ from typing import Type
8
+
9
+ __all__ = (
10
+ 'Inner'
11
+ )
12
+
13
+
14
+ class Inner(Join):
15
+ """Inner Join Class"""
16
+
17
+ def __init__(self, table: Type[Dataclass], *args) -> None:
18
+ super(Inner, self).__init__('INNER', table, *args)
19
+ return
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ..Expr import Expr
4
+
5
+ from ..Mapping import (
6
+ identifier,
7
+ inspect_model,
8
+ )
9
+
10
+ from typing import Type
11
+
12
+ __all__ = (
13
+ 'Join'
14
+ )
15
+
16
+
17
+ class Join(Expr):
18
+ """Join Class"""
19
+
20
+ def __init__(self, expr: str, table: Type, *args) -> None:
21
+ self.expr = expr
22
+ self.table = inspect_model(table)
23
+ self.args = args
24
+ return
25
+
26
+ def __str__(self):
27
+ return '{} JOIN {} ON {}'.format(
28
+ self.expr,
29
+ identifier(self.table.name),
30
+ ' AND '.join([str(arg) for arg in self.args]),
31
+ )