gibson-cli 0.6.0__py3-none-any.whl → 0.7.0__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 (59) hide show
  1. bin/clean.sh +3 -0
  2. gibson/api/BaseApi.py +2 -1
  3. gibson/api/Cli.py +9 -2
  4. gibson/command/Build.py +60 -8
  5. gibson/command/Help.py +0 -12
  6. gibson/command/Question.py +4 -7
  7. gibson/command/code/Code.py +42 -12
  8. gibson/command/code/Entity.py +25 -7
  9. gibson/command/code/Model.py +1 -1
  10. gibson/command/code/Schema.py +1 -1
  11. gibson/command/code/Test.py +35 -0
  12. gibson/command/code/Tests.py +12 -21
  13. gibson/command/importer/Import.py +83 -11
  14. gibson/command/importer/OpenApi.py +4 -9
  15. gibson/command/new/Module.py +1 -1
  16. gibson/command/new/New.py +3 -3
  17. gibson/command/new/Project.py +2 -2
  18. gibson/command/rewrite/Rewrite.py +9 -14
  19. gibson/command/tests/test_command_Conf.py +1 -0
  20. gibson/conf/Project.py +1 -0
  21. gibson/core/Configuration.py +21 -58
  22. gibson/core/Conversation.py +25 -7
  23. gibson/data/bash-completion.tmpl +3 -4
  24. gibson/data/postgresql/default-ref-table.tmpl +4 -0
  25. gibson/data/postgresql/default-table.tmpl +5 -0
  26. gibson/db/TableExceptions.py +3 -0
  27. gibson/db/tests/test_db_TableExceptions.py +4 -0
  28. gibson/services/code/context/schema/EntityKeys.py +3 -3
  29. gibson/services/code/context/schema/tests/test_code_context_schema_EntityKeys.py +3 -3
  30. gibson/structure/Entity.py +12 -109
  31. gibson/structure/mysql/Entity.py +117 -0
  32. gibson/structure/{constraints → mysql/constraints}/ReferenceConstraint.py +6 -2
  33. gibson/structure/{keys → mysql/keys}/ForeignKey.py +9 -5
  34. gibson/structure/{keys → mysql/keys}/Index.py +7 -3
  35. gibson/structure/{keys/tests/test_ForeignKey.py → mysql/keys/tests/test_structure_mysql_keys_ForeignKey.py} +16 -8
  36. gibson/structure/{keys/tests/test_Index.py → mysql/keys/tests/test_structure_mysql_keys_Index.py} +7 -3
  37. gibson/structure/{keys/tests/test_IndexAttribute.py → mysql/keys/tests/test_structure_mysql_keys_IndexAttribute.py} +1 -1
  38. gibson/structure/mysql/testing.py +231 -0
  39. gibson/structure/{tests/test_Entity.py → mysql/tests/test_structure_mysql_Entity.py} +34 -20
  40. gibson/structure/postgresql/Entity.py +108 -0
  41. gibson/structure/postgresql/References.py +61 -0
  42. gibson/structure/postgresql/table/ForeignKey.py +28 -0
  43. gibson/structure/postgresql/table/tests/test_structure_postgresql_table_ForeignKey.py +44 -0
  44. gibson/structure/{testing.py → postgresql/testing.py} +45 -82
  45. gibson/structure/postgresql/tests/test_structure_postgresql_Entity.py +82 -0
  46. gibson/structure/tests/test_structure_Entity.py +22 -0
  47. {gibson_cli-0.6.0.dist-info → gibson_cli-0.7.0.dist-info}/METADATA +76 -27
  48. {gibson_cli-0.6.0.dist-info → gibson_cli-0.7.0.dist-info}/RECORD +58 -47
  49. {gibson_cli-0.6.0.dist-info → gibson_cli-0.7.0.dist-info}/WHEEL +1 -1
  50. gibson/command/rewrite/Tests.py +0 -26
  51. /gibson/command/{rewrite → code}/Api.py +0 -0
  52. /gibson/command/{rewrite → code}/Base.py +0 -0
  53. /gibson/command/{rewrite → code}/Models.py +0 -0
  54. /gibson/command/{rewrite → code}/Schemas.py +0 -0
  55. /gibson/data/{default-ref-table.tmpl → mysql/default-ref-table.tmpl} +0 -0
  56. /gibson/data/{default-table.tmpl → mysql/default-table.tmpl} +0 -0
  57. /gibson/structure/{keys → mysql/keys}/IndexAttribute.py +0 -0
  58. {gibson_cli-0.6.0.dist-info → gibson_cli-0.7.0.dist-info}/entry_points.txt +0 -0
  59. {gibson_cli-0.6.0.dist-info → gibson_cli-0.7.0.dist-info}/top_level.txt +0 -0
@@ -3,17 +3,16 @@ import shutil
3
3
  import sys
4
4
 
5
5
  import gibson.core.Colors as Colors
6
+ from gibson.command.BaseCommand import BaseCommand
7
+ from gibson.command.code.Api import Api
8
+ from gibson.command.code.Base import Base
9
+ from gibson.command.code.Models import Models
10
+ from gibson.command.code.Schemas import Schemas
11
+ from gibson.command.code.Tests import Tests
6
12
  from gibson.core.Configuration import Configuration
7
13
  from gibson.core.TimeKeeper import TimeKeeper
8
14
  from gibson.services.code.customization.CustomizationManager import CustomizationManager
9
15
 
10
- from ..BaseCommand import BaseCommand
11
- from .Api import Api
12
- from .Base import Base
13
- from .Models import Models
14
- from .Schemas import Schemas
15
- from .Tests import Tests
16
-
17
16
 
18
17
  class Rewrite(BaseCommand):
19
18
  def __init__(
@@ -29,10 +28,8 @@ class Rewrite(BaseCommand):
29
28
  self.arguments = ["api", "base", "models", "schemas", "tests"]
30
29
 
31
30
  def execute(self):
32
- if len(sys.argv) != 3:
31
+ if len(sys.argv) == 2:
33
32
  self.write()
34
- elif sys.argv[2] in self.arguments:
35
- self.write(sys.argv[2])
36
33
  else:
37
34
  self.usage()
38
35
 
@@ -66,7 +63,8 @@ class Rewrite(BaseCommand):
66
63
  time_keeper = TimeKeeper()
67
64
  self.conversation.type(" API ")
68
65
  self.conversation.mute()
69
- # Disable customization management here so we don't process this twice (see finally block)
66
+ # Disable customization management here so we don't process this
67
+ # twice (see finally block).
70
68
  Api(self.configuration).disable_customization_management().execute()
71
69
  self.conversation.unmute()
72
70
  self.conversation.type(time_keeper.get_display())
@@ -120,8 +118,5 @@ class Rewrite(BaseCommand):
120
118
  self.conversation.type(
121
119
  f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('rewrite')} {Colors.hint('rewrite all code')}\n"
122
120
  )
123
- self.conversation.type(
124
- f" {Colors.command(self.configuration.command)} {Colors.subcommand('rewrite')} {Colors.arguments(self.arguments)} {Colors.hint('rewrite only the specified code')}\n"
125
- )
126
121
  self.conversation.newline()
127
122
  exit(1)
@@ -4,6 +4,7 @@ from gibson.core.Configuration import Configuration
4
4
 
5
5
  def test_get_configuration_keys():
6
6
  assert Conf(Configuration()).get_configuration_keys() == [
7
+ "id",
7
8
  "api::key",
8
9
  "code::custom::model::class",
9
10
  "code::custom::model::path",
gibson/conf/Project.py CHANGED
@@ -8,6 +8,7 @@ from .Paths import ProjectPaths
8
8
 
9
9
  class Project:
10
10
  def __init__(self):
11
+ self.id = None
11
12
  self.api = Api()
12
13
  self.code = Code()
13
14
  self.datastore = Datastore()
@@ -1,9 +1,7 @@
1
1
  import errno
2
2
  import json
3
3
  import os
4
- import shutil
5
4
  import sys
6
- import time
7
5
 
8
6
  from gibson.conf.Dependencies import Dependencies
9
7
  from gibson.conf.Paths import ConfigPaths
@@ -61,8 +59,11 @@ class Configuration:
61
59
  "production": "da287371-240b-4b53-bfde-4b1581cca62a",
62
60
  }[self.API_ENV]
63
61
 
64
- def append_project_to_conf(self, project_name, project_description):
62
+ def append_project_to_conf(
63
+ self, project_name, project_description, project_id=None
64
+ ):
65
65
  self.project = Project()
66
+ self.project.id = project_id
66
67
  self.project.api.key = "FIXME"
67
68
  self.project.name = project_name
68
69
  self.project.datastore.type = "mysql"
@@ -71,62 +72,11 @@ class Configuration:
71
72
 
72
73
  dependencies = Dependencies().compute()
73
74
 
74
- section = f""""{self.project.name}": {{
75
- "api": {{
76
- "key": "{self.project.api.key}"
77
- }},
78
- "code": {{
79
- "custom": {{
80
- "model": {{
81
- "class": None,
82
- "path": None
83
- }}
84
- }},
85
- "frameworks": {{
86
- "api": "{dependencies.api}",
87
- "model": "{dependencies.model}",
88
- "revision": "{dependencies.revision}",
89
- "schema": "{dependencies.schema}",
90
- "test": "{dependencies.test}",
91
- }},
92
- "language": "python"
93
- }},
94
- "datastore": {{
95
- "type": "{self.project.datastore.type}",
96
- "uri": "{self.project.datastore.uri}"
97
- }},
98
- "dev": {{
99
- "active": False,
100
- "api": {{
101
- "path": None,
102
- "prefix": "-",
103
- "version": "v1"
104
- }},
105
- "base": {{
106
- "path": None
107
- }},
108
- "model": {{
109
- "path": None
110
- }},
111
- "schema": {{
112
- "path": None
113
- }}
114
- }},
115
- "meta": {{
116
- "project": {{
117
- "description": "{self.project.description}"
118
- }},
119
- "version": {self.VERSION}
120
- }},
121
- "modeler": {{
122
- "version": "generic-v7"
123
- }}
124
- }}"""
125
-
126
75
  if self.settings is None:
127
76
  self.settings = {}
128
77
 
129
78
  self.settings[self.project.name] = {
79
+ "id": self.project.id,
130
80
  "api": {"key": self.project.api.key},
131
81
  "code": {
132
82
  "custom": {"model": {"class": None, "path": None}},
@@ -161,7 +111,10 @@ class Configuration:
161
111
 
162
112
  self.write_config()
163
113
 
164
- return section
114
+ # Return a printable version of the project configuration
115
+ return json.dumps(
116
+ {self.project.name: self.settings[self.project.name]}, indent=2
117
+ )
165
118
 
166
119
  def ask_for_path(self, current_value):
167
120
  while True:
@@ -243,6 +196,12 @@ class Configuration:
243
196
 
244
197
  self.settings[project_name] = conf
245
198
 
199
+ if conf["meta"]["version"] == 2:
200
+ if "id" not in conf:
201
+ # Add the project ID and make it the first key in the project config
202
+ conf = dict({"id": None}, **conf)
203
+ self.settings[project_name] = conf
204
+
246
205
  self.write_config()
247
206
 
248
207
  return self
@@ -256,8 +215,11 @@ class Configuration:
256
215
  raise
257
216
 
258
217
  def display_project(self):
218
+ project_name = "[None]"
259
219
  if self.project is not None:
260
- self.conversation.display_project(self.project.name)
220
+ project_name = self.project.name
221
+
222
+ self.conversation.display_project(project_name)
261
223
 
262
224
  def get_access_token(self):
263
225
  try:
@@ -295,7 +257,7 @@ class Configuration:
295
257
 
296
258
  self.conversation.message_project_setup()
297
259
  project_name = self.conversation.prompt_project()
298
- project_description = self.conversation.prompt_description(project_name)
260
+ project_description = self.conversation.prompt_project_description(project_name)
299
261
 
300
262
  self.conversation.message_new_project(project_name)
301
263
  self.conversation.pause()
@@ -420,6 +382,7 @@ class Configuration:
420
382
  if config is None or self.project is None:
421
383
  return self
422
384
 
385
+ self.project.id = config.get("id")
423
386
  self.project.api.key = config["api"]["key"]
424
387
  self.project.code.custom.model_class = config["code"]["custom"]["model"][
425
388
  "class"
@@ -82,6 +82,9 @@ class Conversation:
82
82
  )
83
83
  return self
84
84
 
85
+ def file_not_found(self, file_path):
86
+ self.type(f'404, My Friend. Cannot find file "{file_path}".\n')
87
+
85
88
  def gibsonai_project_not_set(self, configuration):
86
89
  self.type(
87
90
  "\nYou have to set the environment variable GIBSONAI_PROJECT "
@@ -227,13 +230,6 @@ class Conversation:
227
230
  )
228
231
  self.newline()
229
232
 
230
- def prompt_description(self, project_name):
231
- while True:
232
- self.type(f"Tell me about {project_name}. Don't be shy > ")
233
- user_prompt = input("")
234
- if len(user_prompt) > 0:
235
- return user_prompt
236
-
237
233
  def prompt_module(self):
238
234
  while True:
239
235
  self.type("Module Name [a-z0-9] > ")
@@ -248,6 +244,28 @@ class Conversation:
248
244
  if re.search("^[A-Za-z0-9_-]+$", user_prompt):
249
245
  return user_prompt
250
246
 
247
+ def prompt_project_description(self, project_name):
248
+ while True:
249
+ self.type(f"Tell me about {project_name}. Don't be shy > ")
250
+ user_prompt = input("")
251
+ if len(user_prompt) > 0:
252
+ return user_prompt
253
+
254
+ def prompt_project_id(self):
255
+ while True:
256
+ self.type("Project ID (UUID) > ")
257
+ user_prompt = input("")
258
+
259
+ if user_prompt == "":
260
+ return None
261
+
262
+ if re.search(
263
+ "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$",
264
+ user_prompt,
265
+ re.IGNORECASE,
266
+ ):
267
+ return user_prompt
268
+
251
269
  def raw_llm_response(self):
252
270
  print("\n+" + "-" * 75 + "+")
253
271
  print("| Raw LLM Response" + " " * 58 + "|")
@@ -57,15 +57,14 @@ __gibson_completions() {
57
57
  case "${previous_word}" in
58
58
  gibson) __gibson_commands_and_options ;;
59
59
  auth) __gibson_generate_completion "login logout" ;;
60
- code) __gibson_generate_completion "entity model schema tests" ;;
61
- conf) __gibson_generate_completion "api::key code::custom::model::class code::custom::path datastore::uri datastore::type" ;;
60
+ code) __gibson_generate_completion "api base entity models schemas tests" ;;
61
+ conf) __gibson_generate_completion "id api::key code::custom::model::class code::custom::model::path code::frameworks::api code::frameworks::model code::frameworks::revision code::frameworks::schema code::frameworks::test code::language datastore::type datastore::uri meta::project::description" ;;
62
62
  dev) __gibson_generate_completion "on off" ;;
63
63
  forget) __gibson_generate_completion "stored last all" ;;
64
- import) __gibson_generate_completion "api datastore openapi" ;;
64
+ import) __gibson_generate_completion "api mysql pg_dump openapi" ;;
65
65
  list) __gibson_generate_completion "entities projects" ;;
66
66
  new) __gibson_generate_completion "project module entity" ;;
67
67
  rename) __gibson_generate_completion "entity" ;;
68
- rewrite) __gibson_generate_completion "api base models schemas tests" ;;
69
68
  esac
70
69
 
71
70
  return 0
@@ -0,0 +1,4 @@
1
+ create table $entity_name (
2
+ id bigint primary key generated always as identity,
3
+ value text unique
4
+ )
@@ -0,0 +1,5 @@
1
+ create table $entity_name (
2
+ id bigint primary key generated always as identity,
3
+ uuid varchar(36) unique not null,
4
+ date_created timestamptz with time zone default now() not null
5
+ )
@@ -2,5 +2,8 @@ class TableExceptions:
2
2
  def mysql(self):
3
3
  return self.universal()
4
4
 
5
+ def postgresql(self):
6
+ return self.universal()
7
+
5
8
  def universal(self):
6
9
  return ["alembic_version"]
@@ -7,3 +7,7 @@ def test_universal():
7
7
 
8
8
  def test_mysql():
9
9
  assert TableExceptions().mysql() == ["alembic_version"]
10
+
11
+
12
+ def test_postgresql():
13
+ assert TableExceptions().postgresql() == ["alembic_version"]
@@ -1,6 +1,6 @@
1
- from gibson.structure.constraints.ReferenceConstraint import ReferenceConstraint
2
- from gibson.structure.keys.ForeignKey import ForeignKey
3
- from gibson.structure.keys.Index import Index
1
+ from gibson.structure.mysql.constraints.ReferenceConstraint import ReferenceConstraint
2
+ from gibson.structure.mysql.keys.ForeignKey import ForeignKey
3
+ from gibson.structure.mysql.keys.Index import Index
4
4
 
5
5
 
6
6
  class EntityKeys:
@@ -1,7 +1,7 @@
1
1
  from gibson.services.code.context.schema.EntityKeys import EntityKeys
2
- from gibson.structure.constraints.ReferenceConstraint import ReferenceConstraint
3
- from gibson.structure.keys.ForeignKey import ForeignKey
4
- from gibson.structure.keys.Index import Index
2
+ from gibson.structure.mysql.constraints.ReferenceConstraint import ReferenceConstraint
3
+ from gibson.structure.mysql.keys.ForeignKey import ForeignKey
4
+ from gibson.structure.mysql.keys.Index import Index
5
5
 
6
6
 
7
7
  def test_best_sql_foreign_key_no_match():
@@ -1,115 +1,18 @@
1
- from gibson.structure.keys.ForeignKey import ForeignKey
2
- from gibson.structure.keys.Index import Index
1
+ from gibson.structure.mysql.Entity import Entity as MysqlEntity
2
+ from gibson.structure.postgresql.Entity import Entity as PostgresqlEntity
3
3
 
4
4
 
5
5
  class Entity:
6
- def __init__(self):
7
- self.attributes = None
8
- self.constraints = None
9
- self.keys = None
10
- self.name = None
11
- self.parameters = None
6
+ TYPE_MYSQL = "mysql"
7
+ TYPE_POSTGRESQL = "postgresql"
12
8
 
13
- def add_attribute(self, name, data_type, after=None, before=None):
14
- was_added = False
9
+ def instantiate(self, datastore_type: str):
10
+ if datastore_type not in [self.TYPE_MYSQL, self.TYPE_POSTGRESQL]:
11
+ raise RuntimeError(f'unrecognized datastore type "{datastore_type}"')
15
12
 
16
- json = {
17
- "as": None,
18
- "bytes": None,
19
- "check": None,
20
- "comment": None,
21
- "data_type": {
22
- "formatted": data_type,
23
- "raw": data_type,
24
- },
25
- "default": None,
26
- "extra": {"increment": {"auto": None}},
27
- "key": {"index": None, "primary": None, "unique": None},
28
- "length": None,
29
- "name": name,
30
- "nullable": None,
31
- "numeric": {
32
- "precision": None,
33
- "scale": None,
34
- },
35
- "on": None,
36
- "reference": None,
37
- "sql": f"{name} {data_type}",
38
- "unsigned": None,
39
- "values": None,
40
- }
13
+ if datastore_type == self.TYPE_MYSQL:
14
+ return MysqlEntity()
15
+ elif datastore_type == self.TYPE_POSTGRESQL:
16
+ return PostgresqlEntity()
41
17
 
42
- attributes = []
43
- for attribute in self.attributes:
44
- if was_added is False and attribute["name"] == after:
45
- was_added = True
46
- attributes.append(attribute)
47
- attributes.append(json)
48
- elif was_added is False and attribute["name"] == before:
49
- was_added = True
50
- attributes.append(json)
51
- attributes.append(attribute)
52
- else:
53
- attributes.append(attribute)
54
-
55
- if was_added is False:
56
- attributes.append(json)
57
-
58
- self.attributes = attributes
59
- return self
60
-
61
- def add_foreign_key(self, foreign_key: ForeignKey):
62
- self.keys["foreign"].append(foreign_key.json())
63
- return self
64
-
65
- def add_index(self, index: Index):
66
- self.keys["index"].append(index.json())
67
- return self
68
-
69
- def create_statement(self):
70
- parts = []
71
- for attribute in self.attributes:
72
- parts.append(" " + attribute["sql"])
73
-
74
- if self.keys["primary"] is not None:
75
- parts.append(" " + self.keys["primary"]["sql"])
76
-
77
- for unique_key in self.keys["unique"]:
78
- parts.append(" " + unique_key["sql"])
79
-
80
- for index in self.keys["index"]:
81
- parts.append(" " + index["sql"])
82
-
83
- for fk in self.keys["foreign"]:
84
- parts.append(" " + fk["sql"])
85
-
86
- for check in self.constraints["check"]:
87
- parts.append(" " + check["sql"])
88
-
89
- parameters = self.parameters["sql"]
90
- if parameters not in [None, ""]:
91
- parameters = " " + parameters
92
- else:
93
- parameters = ""
94
-
95
- return (
96
- f"create table if not exists {self.name}(\n"
97
- + ",\n".join(parts)
98
- + f"\n){parameters}"
99
- )
100
-
101
- def import_from_struct(self, data: dict):
102
- if "name" in data and "struct" in data:
103
- self.name = data["name"]
104
-
105
- for key in data["struct"].keys():
106
- setattr(self, key, data["struct"][key])
107
- elif "entity" in data and "struct" in data["entity"]:
108
- self.name = data["entity"]["name"]
109
-
110
- for key in data["entity"]["struct"].keys():
111
- setattr(self, key, data["entity"]["struct"][key])
112
- else:
113
- raise RuntimeError("cannot import from struct, incorrect data format")
114
-
115
- return self
18
+ raise NotImplementedError(f'"{datastore_type}" is not currently supported')
@@ -0,0 +1,117 @@
1
+ from gibson.structure.mysql.keys.ForeignKey import ForeignKey
2
+ from gibson.structure.mysql.keys.Index import Index
3
+
4
+
5
+ class Entity:
6
+ def __init__(self):
7
+ self.attributes = None
8
+ self.constraints = None
9
+ self.keys = None
10
+ self.name = None
11
+ self.table = None
12
+
13
+ def add_attribute(self, name, data_type, after=None, before=None):
14
+ was_added = False
15
+
16
+ json = {
17
+ "check": None,
18
+ "datastore": {
19
+ "specifics": {
20
+ "as": None,
21
+ "bytes": None,
22
+ "comment": None,
23
+ "extra": {"increment": {"auto": None}},
24
+ "on": None,
25
+ "reference": None,
26
+ "unsigned": None,
27
+ "values": None,
28
+ }
29
+ },
30
+ "data_type": {
31
+ "formatted": data_type,
32
+ "raw": data_type,
33
+ },
34
+ "default": None,
35
+ "key": {"index": None, "primary": None, "unique": None},
36
+ "length": None,
37
+ "name": name,
38
+ "nullable": None,
39
+ "numeric": {
40
+ "precision": None,
41
+ "scale": None,
42
+ },
43
+ "sql": f"{name} {data_type}",
44
+ }
45
+
46
+ attributes = []
47
+ for attribute in self.attributes:
48
+ if was_added is False and attribute["name"] == after:
49
+ was_added = True
50
+ attributes.append(attribute)
51
+ attributes.append(json)
52
+ elif was_added is False and attribute["name"] == before:
53
+ was_added = True
54
+ attributes.append(json)
55
+ attributes.append(attribute)
56
+ else:
57
+ attributes.append(attribute)
58
+
59
+ if was_added is False:
60
+ attributes.append(json)
61
+
62
+ self.attributes = attributes
63
+ return self
64
+
65
+ def add_foreign_key(self, foreign_key: ForeignKey):
66
+ self.keys["foreign"].append(foreign_key.json())
67
+ return self
68
+
69
+ def add_index(self, index: Index):
70
+ self.keys["index"].append(index.json())
71
+ return self
72
+
73
+ def create_statement(self):
74
+ parts = []
75
+ for attribute in self.attributes:
76
+ parts.append(" " + attribute["sql"])
77
+
78
+ if self.keys["primary"] is not None:
79
+ parts.append(" " + self.keys["primary"]["sql"])
80
+
81
+ for unique_key in self.keys["unique"]:
82
+ parts.append(" " + unique_key["sql"])
83
+
84
+ for index in self.keys["index"]:
85
+ parts.append(" " + index["sql"])
86
+
87
+ for fk in self.keys["foreign"]:
88
+ parts.append(" " + fk["sql"])
89
+
90
+ for check in self.constraints["check"]:
91
+ parts.append(" " + check["sql"])
92
+
93
+ parameters = ""
94
+ if self.table["parameters"] and self.table["parameters"].get("sql"):
95
+ parameters = " " + self.table["parameters"].get("sql")
96
+
97
+ return (
98
+ f"create table if not exists {self.name}(\n"
99
+ + ",\n".join(parts)
100
+ + f"\n){parameters}"
101
+ )
102
+
103
+ def import_from_struct(self, data: dict):
104
+ if "name" in data and "struct" in data:
105
+ self.name = data["name"]
106
+
107
+ for key in data["struct"].keys():
108
+ setattr(self, key, data["struct"][key])
109
+ elif "entity" in data and "struct" in data["entity"]:
110
+ self.name = data["entity"]["name"]
111
+
112
+ for key in data["entity"]["struct"].keys():
113
+ setattr(self, key, data["entity"]["struct"][key])
114
+ else:
115
+ raise RuntimeError("cannot import from struct, incorrect data format")
116
+
117
+ return self
@@ -9,9 +9,13 @@ class ReferenceConstraint:
9
9
  def json(self):
10
10
  return {
11
11
  "attributes": self.attributes,
12
- "match": self.match,
12
+ "datastore": {
13
+ "specifics": {
14
+ "match": self.match,
15
+ }
16
+ },
17
+ "entity": {"name": self.references, "schema_": None},
13
18
  "on": {"delete": self.on_delete, "update": self.on_update},
14
- "references": self.references,
15
19
  "sql": self.sql(),
16
20
  }
17
21
 
@@ -1,4 +1,4 @@
1
- from gibson.structure.constraints.ReferenceConstraint import ReferenceConstraint
1
+ from gibson.structure.mysql.constraints.ReferenceConstraint import ReferenceConstraint
2
2
 
3
3
 
4
4
  class ForeignKey:
@@ -12,11 +12,15 @@ class ForeignKey:
12
12
  def json(self):
13
13
  return {
14
14
  "attributes": self.attributes,
15
- "name": self.name,
16
- "reference": self.reference.json(),
17
- "relationship": {"type": None},
15
+ "datastore": {
16
+ "specifics": {
17
+ "name": self.name,
18
+ "relationship": {"type": None},
19
+ "symbol": self.symbol,
20
+ }
21
+ },
22
+ "references": self.reference.json(),
18
23
  "sql": self.sql(),
19
- "symbol": self.symbol,
20
24
  }
21
25
 
22
26
  def sql(self):
@@ -1,4 +1,4 @@
1
- from gibson.structure.keys.IndexAttribute import IndexAttribute
1
+ from gibson.structure.mysql.keys.IndexAttribute import IndexAttribute
2
2
 
3
3
 
4
4
  class Index:
@@ -34,9 +34,13 @@ class Index:
34
34
  def json(self):
35
35
  return {
36
36
  "attributes": self.__attribute_name_list,
37
- "name": self.name,
37
+ "datastore": {
38
+ "specifics": {
39
+ "name": self.name,
40
+ "using": self.using,
41
+ }
42
+ },
38
43
  "sql": self.sql(),
39
- "using": self.using,
40
44
  }
41
45
 
42
46
  def reset_attributes(self):