Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

1.4 KB
Raw Blame
import { v1 as uuidv1 } from "uuid";
import type { SQLEditorConnection, SQLEditorTab } from "@/types";
import {
  DEFAULT_SQL_EDITOR_TAB_MODE,
  defaultViewState,
  UNKNOWN_DATABASE_NAME,
} from "@/types";

export const defaultSQLEditorTab = (): SQLEditorTab => {
  return {
    id: uuidv1(),
    // Tabs are created untitled. The UI renders a localized "Untitled"
    // placeholder when the title is empty; users name saved queries explicitly
    // when (and if) they save.
    title: "",
    connection: emptySQLEditorConnection(),
    statement: "",
    selectedStatement: "",
    status: "CLEAN",
    mode: DEFAULT_SQL_EDITOR_TAB_MODE,
    savedQuery: "",
    treeState: {
      database: UNKNOWN_DATABASE_NAME,
      keys: [],
    },
    editorState: {
      selection: null,
    },
    viewState: defaultViewState(),
    batchQueryContext: {
      databases: [],
    },
  };
};

export const emptySQLEditorConnection = (): SQLEditorConnection => {
  return {
    instance: "",
    database: "",
  };
};

export const isSameSQLEditorConnection = (
  a: SQLEditorConnection,
  b: SQLEditorConnection
): boolean => {
  return a.instance === b.instance && a.database === b.database;
};

// `getConnectionForSQLEditorTab` / `isConnectedSQLEditorTab` and
// `getValidDataSourceByPolicy` moved to `@/lib/*` so the database and
// policy lookups read the React app store directly without dragging
// `@/stores/app` into the `@/utils` import graph (a static ESM cycle).