sqlectron / sqlectron-gui

A simple and lightweight SQL client desktop with cross database and platform support.
https://sqlectron.github.io/
MIT License
4.58k stars 525 forks source link

CockroachDB? #312

Open bitjson opened 7 years ago

bitjson commented 7 years ago

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.

maxcnunes commented 7 years ago

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
fire commented 7 years ago

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 commented 7 years ago
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.

maxcnunes commented 7 years ago

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

fire commented 7 years ago

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

I'm on Windows.

maxcnunes commented 7 years ago
fire commented 7 years ago

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.

dunhamjared commented 7 years ago

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

fire commented 7 years ago

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.