isaac-mcfadyen / d1-jdbc-driver

A JDBC driver for Cloudflare's D1 product, compatible with Jetbrains tools.
GNU General Public License v3.0
86 stars 5 forks source link

Implement foreign key constraints. #4

Open kinda-raffy opened 8 months ago

kinda-raffy commented 8 months ago

Hi @isaac-mcfadyen,

Love your work!

Correct me if I'm wrong, but it seems like the database driver has no conception of foreign keys in the databases, right?

For example, the Locality table should hold a foreign key to the Region table via the attribute regionId. But the driver only seems to pick up the primary key only:

image

It also fails to produce any edges between the two tables in the diagram viewer:

image

For clarity, here is the SQL code that created these tables:

CREATE TABLE `Region` (
    `regionId` text PRIMARY KEY NOT NULL,
    `regionName` text NOT NULL
);

CREATE TABLE `Locality` (
    `localityId` text PRIMARY KEY NOT NULL,
    `localityName` text NOT NULL,
    `regionId` text NOT NULL,
    FOREIGN KEY (`regionId`) REFERENCES `Region`(`regionId`) ON UPDATE cascade ON DELETE cascade
);

I understand that there is an issue with showing foreign keys and I'm willing to code up a solution to this. Before I get started, could you please point me in the right direction?

Thanks, Raf.