better / jsonschema2db

Generate tables dynamically from a JSON Schema and insert data

Home Page:https://better.engineering/jsonschema2db/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

where to pass table name? can you give simple ?

rmohamedfazil opened this issue · comments

I am using jsonschema2db package, I tried to create a table in the example it's given by you in jsonschema2db documentation, it's working fine but I don't understand much about an example because you using reference also. where to pass table name it's default taking table name is root. can you give simple example using JSON like {'id':{'type':'string'},'name':{'type':'string'}} for example 2 or 3 column enough.

@rmohamedfazil To achieve custom root schema name, you might need to modify JSONSchemaToDatabase constructor in jsonschema2db.py by doing the following:

  • add a new constructor parameter e.g. root_table_name
  • override the default value ('root') for table parameter of _traverse method by passing this new argument:
    self._translation_tree = self._traverse(schema, schema, comment=schema.get('comment'), table=root_table_name)