buildAutoCompletes = async () => {
	const columnsQuery = `
SELECT  concat(tables.table_schema, '.', tables.table_name) as qualifiedTable,
	column_name as label,
	ordinal_position as ordinal,
	* 
FROM information_schema.tables
INNER JOIN information_schema.columns 
ON  tables.table_name = columns.table_name 
  AND tables.table_schema = columns.table_schema`.trim();
	/** @typedef {{qualifiedTable: string; table_name: string, ordinal: number, table_schema: string, label: string; data_type: string; is_nullable: 'YES' | 'NO'}} SchemaRow */

	const columnsData = buildQuery(columnsQuery);
	await columnsData.fetch();
	if (columnsData.error) throw columnsData.error;
	/** @type {SQLConfig['schema']} */
	const columns = columnsData.reduce(
		(/** @type {Record<string, Completion[]>} */ a, /** @type { SchemaRow } */ row) => {
			if (!(row.qualifiedTable in a)) a[row.qualifiedTable] = [];

			const nullStr = row.is_nullable === 'YES' ? '' : '(NOT NULL)';
			a[row.qualifiedTable].push({
				label: row.label,
				type: 'property',
				detail: `${row.data_type} ${nullStr}`,
				boost: Math.floor(100 / row.ordinal)
			});

			return a;
		},
		{}
	);
	const tablesQuery = `
		SELECT  concat(tables.table_schema, '.', tables.table_name) as qualifiedTable,
			* 
		FROM information_schema.tables`.trim();

	const tablesData = buildQuery(tablesQuery);
	await tablesData.fetch();
	if (tablesData.error) throw tablesData.error;
	/** @type {SQLConfig['tables']} */
	const tables = tablesData.map((/** @type { SchemaRow } */ row) => {
		/** @type {SQLConfig['tables'][number]} */
		const completion = {
			label: row.qualifiedTable,
			displayLabel: row.table_name,
			detail: row.table_schema,
			type: 'class',
			info: (cmp) => {
				const colCompletions = columns[cmp.label];
				const dl = document.createElement('dl');
				dl.classList.add('grid-cols-2', 'grid', 'gap-x-4');

				colCompletions.forEach((cc) => {
					const term = document.createElement('dt');
					term.classList.add('overflow-hidden', 'truncate', 'text-ellipsis');
					term.textContent = cc.label;

					const def = document.createElement('dd');
					def.textContent = cc.detail;

					dl.appendChild(term);
					dl.appendChild(def);
				});

				return dl;
			}
		};

		return completion;
	});

	const schemas = Object.values(
		tablesData.reduce(
			(/** @type {Record<string, Completion>} */ a, /** @type { SchemaRow } */ row) => {
				if (!a[row.label]) {
					/** @type {Completion} */
					const schemaCompletion = {
						label: row.table_schema,
						type: 'namespace',
						info: (completion) => {
							const tableCompletions = tables.filter((t) => t.label.startsWith(completion.label));

							const dl = document.createElement('dl');
							dl.classList.add('grid-cols-2', 'grid', 'gap-x-4');
							tableCompletions.forEach((cc) => {
								const term = document.createElement('dt');
								term.classList.add('overflow-hidden', 'truncate', 'text-ellipsis');
								term.textContent = cc.displayLabel;

								const def = document.createElement('dd');
								def.textContent = cc.detail;

								dl.appendChild(term);
								dl.appendChild(def);
							});

							return dl;
						}
					};
					a[row.label] = schemaCompletion;
				}

				return a;
			},
			{}
		)
	);

	return {
		schema: columns,
		tables,
		schemas
	};
}
@returns {{schema: SQLConfig['schema'], tables: SQLConfig['tables']}}