Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Node Structure Change: Create Foreign Key #32

Open
jdrew1303 opened this issue Oct 24, 2016 · 1 comment
Open

Node Structure Change: Create Foreign Key #32

jdrew1303 opened this issue Oct 24, 2016 · 1 comment

Comments

@jdrew1303
Copy link

jdrew1303 commented Oct 24, 2016

Input

{
  "type": "definition",
  "variant": "constraint",
  "definition": [
    {
      "type": "constraint",
      "variant": "foreign key",
      "references": {
        "type": "identifier",
        "variant": "table",
        "name": "hives"
      }
    }
  ],
  "columns": [
    {
      "type": "identifier",
      "variant": "column",
      "name": "hive_id"
    }
  ]
}

Output

FOREIGN KEY (hive_id) REFERENCES Hives

Issue

With the current structure of this node and the resulting text it's hard to build a generator that can handle this in a generic way. The generator recurses down the tree. By the time we reach the node to know that its a foreign key we have moved passed the other data necessary to build the sql. The 2 identifiers can be on a lower level but the foreign key part needs to be on a higher level.

To get an idea of the issue if you take a look at this line to see how it recourses down the tree and then this line to see how other constraint types are handled.

The main issue is the columns property. If we could pull that down into the foreign key node it would mean that I can handle this the same as the other nodes rather than writing code for edge cases if that's ok with you? Im open to other ideas on the generator if you've any (It's still a bit messy so be kind 😛 )?

This is the first node that I've had problems with, there may be more where I run into this problem.

Note this is from the 1.0.0@beta AST

@jdrew1303
Copy link
Author

I've a work around for this at the moment so this can be put on the back burner 😃. Checking for the columns field in the constraint allows me to switch.

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants