GithubHelp home page GithubHelp logo

isaac-mcfadyen / d1-jdbc-driver Goto Github PK

View Code? Open in Web Editor NEW
67.0 3.0 5.0 61 KB

A JDBC driver for Cloudflare's D1 product, compatible with Jetbrains tools.

License: GNU General Public License v3.0

Java 100.00%
cloudflare d1 database jdbc

d1-jdbc-driver's People

Contributors

isaac-mcfadyen avatar thinkami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

d1-jdbc-driver's Issues

Columns not showing up

I added this driver to my WebStorm to be able to look inside my D1 database as I started to develop.

When I got to my second table, no columns was showing up, only one key representing the PK. This also means that all the database references for columns, etc, will be marked as invalid in the code.

I verified that my table was indeed created and correct by running the command wrangler d1 execute DB --command "pragma table_info('table_name')".

The driver is outputting no messages, no errors.

Implement foreign key constraints.

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.

Updating records inline is not working

First, thanks a lot for this project, whatever is available is already amazing to have and is an extreme productivity booster when working with D1 ❤️. Maybe enable GitHub sponsorships?

For the actual issue, just wanted to leave this here for tracking, my knowledge with java or IJ plugins is basically non-existent.

Basically when editing something in a result table from DataGrip and then updating a value does not work as it produces an incompatible value:

image

This results in an error:

prepareStatement(...) must not be null

Instead of saving the changes, I can let it generate the equivalent SQL statement, which is the following:

UPDATE product t
SET t.title = null, t.slug = null
WHERE t.id LIKE 'kd891h' ESCAPE '#';

Unfortunately, when executing this, it also results in an error "invalid query".

The fix for this one at least is easy by removing the alias:

UPDATE product
SET title = null, slug = null
WHERE id LIKE 'kd891h' ESCAPE '#';

and then running it in the db console instead. This will be my workaround for now which is good enough :)

Select anything but * seems to fail

where mytable has a primary key of mykey the follow queries error:
select distinct field from mytable
select field from mytable

They succeed in the CF D1 console.

I tested 3 different tools, just to make sure.

from dbeaver:

org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error: Internal jdbc driver error
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:133)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:600)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$2(SQLQueryJob.java:503)
	at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:190)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:510)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:962)
	at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:4130)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:123)
	at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:190)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:121)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$ResultSetDataPumpJob.run(ResultSetViewer.java:5148)
	at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:105)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.sql.SQLException: Internal jdbc driver error
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.handleExecuteError(JDBCStatementImpl.java:295)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:332)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:131)
	... 12 more
Caused by: org.json.JSONException: JSONObject["ip"] not found.
	at org.json.JSONObject.get(JSONObject.java:587)
	at org.isaacmcfadyen.D1Queryable.generateResultSet(D1Queryable.java:69)
	at org.isaacmcfadyen.D1Statement.execute(D1Statement.java:107)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:330)
	... 13 more

From datagrip:
[2024-01-09 16:16:29] JSONObject["mykey"] not found.

from dbvis:

This is an error produced by the JDBC driver

[Exception Chain]:
1:        This is an error produced by the JDBC driver
2: Root-> (JSONException) JSONObject["company_id"] not found.

[Stack trace]:
com.onseven.dbvis.m.f.t: org.json.JSONException: JSONObject["mykey"] not found.
	at com.onseven.dbvis.m.f.m.xe(Z:1315)
	at com.onseven.dbvis.m.f.r.xe(Z:3203)
	at com.onseven.dbvis.m.f.db.ne(Z:3457)
	at com.onseven.dbvis.m.f.db.ud(Z:2710)
	at com.onseven.dbvis.m.f.c.b.b.cb.f(Z:2440)
	at com.onseven.dbvis.m.f.c.b.b.cb.b(Z:1653)
	at com.onseven.dbvis.m.f.c.b.b.cb.w(Z:617)
	at com.onseven.dbvis.m.f.c.b.k.s(Z:1542)
	at com.onseven.dbvis.m.f.c.g.d(Z:322)
	at com.onseven.dbvis.m.f.c.g.ib(Z:2352)
	at com.onseven.dbvis.m.f.c.g.xe(Z:2910)
	at com.onseven.dbvis.m.f.db.ne(Z:3457)
	at com.onseven.dbvis.m.f.n.c(Z:1374)
	at com.onseven.dbvis.m.f.n.doInBackground(Z:1521)
	at java.desktop/javax.swing.SwingWorker$1.call(SwingWorker.java:304)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.desktop/javax.swing.SwingWorker.run(SwingWorker.java:343)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: org.json.JSONException: JSONObject["mykey"] not found.
	at org.json.JSONObject.get(JSONObject.java:587)
	at org.isaacmcfadyen.D1Queryable.generateResultSet(D1Queryable.java:69)
	at org.isaacmcfadyen.D1Statement.execute(D1Statement.java:107)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at com.onseven.dbvis.jdbc.b.c.d(Z:2806)
	at com.onseven.dbvis.t.i.b(Z:607)
	at com.onseven.dbvis.jdbc.b.g.b(Z:317)
	at com.onseven.dbvis.jdbc.b.c.b(Z:2806)
	at com.onseven.dbvis.jdbc.b.g$_b.call(Z:618)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	... 3 more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.