sqlectron-gui icon indicating copy to clipboard operation
sqlectron-gui copied to clipboard

CockroachDB?

Open bitjson opened this issue 9 years ago • 9 comments

I'd love to see first-class support for CockroachDB – CockroachDB supports the PostgreSQL wire protocol, so it should be relatively simple to add support.

bitjson avatar Apr 12 '17 01:04 bitjson

If someone is interested on implementing this. Here is the steps in a high level:

  1. Duplicate the postgres client - https://github.com/sqlectron/sqlectron-core/blob/master/src/db/clients/postgresql.js
  2. Include the new client in the list of supported dbs - https://github.com/sqlectron/sqlectron-core/blob/master/src/db/clients/index.js
  3. Ensure the tests are passing - https://github.com/sqlectron/sqlectron-core/blob/master/spec/db.spec.js
  4. Link sqlectron-core to sqlectron-gui and test it in the app - https://github.com/sqlectron/sqlectron-gui/blob/master/docs/development/test-core-changes.md
  5. Include a logo - server-db-client-<client_name>.png https://github.com/sqlectron/sqlectron-gui/tree/master/src/renderer/components

maxclaus avatar Apr 24 '17 21:04 maxclaus

listRoutines is the first one mentioned by the cockroachdb staff.

Not exactly sure how to test this on Windows with Cockroachdb.

Also buildSchemaFilter is not correct.

export async function listRoutines(conn, filter) {
  const schemaFilter = buildSchemaFilter(filter, 'pg_catalog');
  const sql = `
    SELECT
      nspname,
      proname,
      typname
    FROM pg_catalog.pg_proc
    JOIN pg_catalog.pg_type t ON prorettype = t.oid
    JOIN pg_catalog.pg_namespace n ON pronamespace = n.oid
    ${schemaFilter ? `WHERE ${schemaFilter}` : ''}
    GROUP BY nspname, proname, typname
    ORDER BY proname, typname
  `;

  const data = await driverExecuteQuery(conn, { query: sql });

  return data.rows.map((row) => ({
    schema: row.mspname,
    routineName: row.proname,
    routineType: row.typname,
  }));
}

fire avatar Aug 14 '17 12:08 fire

SELECT  a.attname as column_name,
        t.typname as data_type
FROM    pg_catalog.pg_attribute a
JOIN    pg_type t ON ( t.oid = a.atttypid )
JOIN    pg_class r ON ( r.oid = a.attrelid )
JOIN    pg_namespace s ON ( s.oid = r.relnamespace )
WHERE   r.relkind = 'r'
AND     s.nspname = 'database_name' 
AND     r.relname = 'table_name';

For listTableColumns(conn, database, table, schema). Note that schema does not exist and only database exists in CockroachDB.

fire avatar Aug 14 '17 13:08 fire

If schema is not supported by the database you can just ignore that value.

maxclaus avatar Aug 14 '17 16:08 maxclaus

What's the best way to interactively modify the client code on sqlectron gui and have it change the code?

I'm on Windows.

fire avatar Aug 19 '17 15:08 fire

  • To run the app from the source https://github.com/sqlectron/sqlectron-gui/blob/master/docs/development/run-from-source.md
  • To rebuild the app automatically on changing the code from sqlectron-core https://github.com/sqlectron/sqlectron-gui/blob/master/docs/development/test-core-changes.md

maxclaus avatar Aug 19 '17 17:08 maxclaus

Won't be able to work on this until next weekend, I've got tables and their columns and constraints shown.

If anyone wants the work I can gist it.

fire avatar Aug 21 '17 04:08 fire

Any updates on this? @fire could you gist it?

dunhamjared avatar Oct 23 '17 14:10 dunhamjared

I can't find my copy anymore.

In my version I made a copy of https://github.com/sqlectron/sqlectron-core/blob/master/src/db/clients/postgresql.js and added https://github.com/sqlectron/sqlectron-gui/issues/312#issuecomment-322185375

Stopped working on it because there was no interest.

fire avatar Oct 23 '17 15:10 fire