Repository navigation
v2.1.1 #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2.1.1 #89
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,17 +20,18 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .pg_log import PgLOG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class PgDBI(PgLOG): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # PostgreSQL specified query timestamp format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmtyr = lambda fn: "extract(year from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmtqt = lambda fn: "extract(quarter from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmtmn = lambda fn: "extract(month from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmtdt = lambda fn: "date({})".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmtym = lambda fn: "to_char({}, 'yyyy-mm')".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmthr = lambda fn: "extract(hour from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super().__init__() # initialize parent class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # PostgreSQL specified query timestamp format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.fmtyr = lambda fn=self: "extract(year from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.fmtqt = lambda fn=self: "extract(quarter from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.fmtmn = lambda fn=self: "extract(month from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.fmtdt = lambda fn=self: "date({})".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.fmtym = lambda fn=self: "to_char({}, 'yyyy-mm')".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.fmthr = lambda fn=self: "extract(hour from {})::int".format(fn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+33
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
24
to
+34
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self): | |
| super().__init__() # initialize parent class | |
| # PostgreSQL specified query timestamp format | |
| self.fmtyr = lambda fn=self: "extract(year from {})::int".format(fn) | |
| self.fmtqt = lambda fn=self: "extract(quarter from {})::int".format(fn) | |
| self.fmtmn = lambda fn=self: "extract(month from {})::int".format(fn) | |
| self.fmtdt = lambda fn=self: "date({})".format(fn) | |
| self.fmtym = lambda fn=self: "to_char({}, 'yyyy-mm')".format(fn) | |
| self.fmthr = lambda fn=self: "extract(hour from {})::int".format(fn) | |
| # PostgreSQL specified query timestamp format | |
| @staticmethod | |
| def fmtyr(fn): | |
| return "extract(year from {})::int".format(fn) | |
| @staticmethod | |
| def fmtqt(fn): | |
| return "extract(quarter from {})::int".format(fn) | |
| @staticmethod | |
| def fmtmn(fn): | |
| return "extract(month from {})::int".format(fn) | |
| @staticmethod | |
| def fmtdt(fn): | |
| return "date({})".format(fn) | |
| @staticmethod | |
| def fmtym(fn): | |
| return "to_char({}, 'yyyy-mm')".format(fn) | |
| @staticmethod | |
| def fmthr(fn): | |
| return "extract(hour from {})::int".format(fn) | |
| def __init__(self): | |
| super().__init__() # initialize parent class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default argument
fn=selfcaptures the instance in the lambda’s__defaults__, creating an unnecessary self-reference cycle and makingself.fmtyr()(no args) format the PgDBI object instead of a field/expression. These formatters don’t needself; define them without aselfdefault (e.g., requirefn), or better, make them@staticmethods to avoid capturing the instance at all.