ProcruSQL 0.0.15__tar.gz → 0.0.16__tar.gz

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.
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ProcruSQL
3
- Version: 0.0.15
3
+ Version: 0.0.16
4
4
  Summary: Make a database fit its description
5
5
  Home-page: https://git.hjp.at:3000/hjp/procrusql
6
6
  Author: Peter J. Holzer
7
7
  Author-email: hjp@hjp.at
8
8
  Project-URL: Bug Tracker, https://git.hjp.at:3000/hjp/procrusql/issues
9
+ Project-URL: Repository, https://git.hjp.at:3000/hjp/procrusql
9
10
  Classifier: Programming Language :: Python :: 3
10
11
  Classifier: License :: OSI Approved :: MIT License
11
12
  Classifier: Operating System :: OS Independent
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = ProcruSQL
3
- version = 0.0.15
3
+ version = 0.0.16
4
4
  author = Peter J. Holzer
5
5
  author_email = hjp@hjp.at
6
6
  description = Make a database fit its description
@@ -9,6 +9,7 @@ long_description_content_type = text/markdown
9
9
  url = https://git.hjp.at:3000/hjp/procrusql
10
10
  project_urls =
11
11
  Bug Tracker = https://git.hjp.at:3000/hjp/procrusql/issues
12
+ Repository = https://git.hjp.at:3000/hjp/procrusql
12
13
  classifiers =
13
14
  Programming Language :: Python :: 3
14
15
  License :: OSI Approved :: MIT License
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ProcruSQL
3
- Version: 0.0.15
3
+ Version: 0.0.16
4
4
  Summary: Make a database fit its description
5
5
  Home-page: https://git.hjp.at:3000/hjp/procrusql
6
6
  Author: Peter J. Holzer
7
7
  Author-email: hjp@hjp.at
8
8
  Project-URL: Bug Tracker, https://git.hjp.at:3000/hjp/procrusql/issues
9
+ Project-URL: Repository, https://git.hjp.at:3000/hjp/procrusql
9
10
  Classifier: Programming Language :: Python :: 3
10
11
  Classifier: License :: OSI Approved :: MIT License
11
12
  Classifier: Operating System :: OS Independent
@@ -48,11 +48,12 @@ class Node:
48
48
  self.order = order
49
49
 
50
50
  class HaveData(Node):
51
- def __init__(self, name, depends, table, key, extra):
51
+ def __init__(self, name, depends, table, key, extra, schema="public"):
52
52
  super().__init__(name, depends)
53
53
  self.table = table
54
54
  self.key = key
55
55
  self.extra = extra
56
+ self.schema = schema
56
57
 
57
58
  def check(self):
58
59
  log_check.info("Checking %s", self.name)
@@ -63,8 +64,9 @@ class HaveData(Node):
63
64
  ]
64
65
  key_check = sql.SQL(" and ").join(key_checks)
65
66
  q = sql.SQL(
66
- "select * from {table} where {key_check}"
67
+ "select * from {schema}.{table} where {key_check}"
67
68
  ).format(
69
+ schema=sql.Identifier(self.schema),
68
70
  table=sql.Identifier(self.table),
69
71
  key_check=key_check
70
72
  )
@@ -78,8 +80,9 @@ class HaveData(Node):
78
80
  if self.result[0][c] != self.extra[c]:
79
81
  log_action.info("Updating %s: %s <- %s", key_values, c, self.extra[c])
80
82
  q = sql.SQL(
81
- "update {table} set {column}={placeholder} where {key_check}"
83
+ "update {schema}.{table} set {column}={placeholder} where {key_check}"
82
84
  ).format(
85
+ schema=sql.Identifier(self.schema),
83
86
  table=sql.Identifier(self.table),
84
87
  column=sql.Identifier(c),
85
88
  placeholder=sql.Placeholder(),
@@ -96,8 +99,9 @@ class HaveData(Node):
96
99
  columns = list(self.key.keys()) + list(self.extra.keys())
97
100
  values = key_values + extra_values
98
101
  q = sql.SQL(
99
- "insert into {table}({columns}) values({placeholders}) returning *"
102
+ "insert into {schema}.{table}({columns}) values({placeholders}) returning *"
100
103
  ).format(
104
+ schema=sql.Identifier(self.schema),
101
105
  table=sql.Identifier(self.table),
102
106
  columns=sql.SQL(", ").join([sql.Identifier(x) for x in columns]),
103
107
  placeholders=sql.SQL(", ").join([sql.Placeholder() for x in columns]),
@@ -43,7 +43,7 @@ class ParseState:
43
43
  linesbefore = self.text[:position].split("\n")
44
44
  linesafter = self.text[position:].split("\n")
45
45
  good = "\x1B[40;32m"
46
- bad = "\x1B[40;31m"
46
+ bad = "\x1B[40;31;1m"
47
47
  reset = "\x1B[0m"
48
48
  s = reset + message + "\n"
49
49
  lines = []
@@ -79,7 +79,8 @@ def parse_ruleset(ps):
79
79
  ps3 = parse_table_rule(ps2) or \
80
80
  parse_column_rule(ps2) or \
81
81
  parse_data_rule(ps2) or \
82
- parse_index_rule(ps2)
82
+ parse_index_rule(ps2) or \
83
+ parse_view_rule(ps2)
83
84
  if ps3:
84
85
  ps2.ast.append(ps3.ast)
85
86
  ps2.position = ps3.position
@@ -273,6 +274,20 @@ def parse_index_rule(ps):
273
274
 
274
275
  return ps2
275
276
 
277
+ def parse_view_rule(ps):
278
+ ps2 = ps.clone()
279
+ ps2.skip_whitespace_and_comments()
280
+ if not ps2.match(r"view\b"):
281
+ ps.record_child_failure(ps2, "expected “view”")
282
+ return
283
+ ps2.skip_whitespace_and_comments()
284
+ ps3 = parse_table_name(ps2)
285
+ if not ps3:
286
+ ps.record_child_failure(ps2, "expected view name")
287
+ return
288
+ ps2.skip_whitespace_and_comments()
289
+ ps3 = parse_multiline_string(ps2)
290
+
276
291
 
277
292
 
278
293
  def parse_table_name(ps):
@@ -340,6 +355,7 @@ def parse_column_definition(ps):
340
355
  "json", "jsonb",
341
356
  "uuid",
342
357
  r"integer\[\]", r"int\[\]", r"bigint\[\]",
358
+ "bytea",
343
359
  ),
344
360
  key=lambda x: -len(x) # longest match first
345
361
  )
File without changes
File without changes
File without changes