Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sqlite_master instead of sqlite_schema #1

Merged
merged 1 commit into from
Jun 20, 2023
Merged

Conversation

mphill
Copy link
Owner

@mphill mphill commented Jun 20, 2023

As of sqlite-3.33.0, the internal table formerly known as sqlite_master was aliased to sqlite_schema.

There is a mismatch in the schema name being references in the sqlite inspector, in one query sqlite_schema is used, then directly after sqlite_master is used.

They renamed sqlite_master to sqlite_schema, but both exist at this point and will for the foreseeable future.

For maximum compatibility use sqlite_master.

Another option could be to do something like this in the inspector:

const version = await sql`select sqlite_version() as version;`.execute(
	this.#db,
);

const isOld = isVersionLessThan(version.rows[0].version, "3.33.0");

let query = this.#db
	.selectFrom(isOld ? "sqlite_master" : "sqlite_schema")
	.where("type", "in", ["table", "view"])
	.where("name", "not like", "sqlite_%")
	.select("name")
	.orderBy("name")
	.$castTo<{ name: string }>();
function isVersionLessThan(version: string, targetVersion: string): boolean {
	const versionParts = version.split(".");
	const targetVersionParts = targetVersion.split(".");

	for (let i = 0; i < versionParts.length; i++) {
		const versionPart = parseInt(versionParts[i]);
		const targetVersionPart = parseInt(targetVersionParts[i]);

		if (versionPart < targetVersionPart) {
			return true;
		}
	}

	return false;
}

…r to 3.33.0 work

There is a mismatch in the schema name being used in the inspector, in one query sqlite_schema is used, then directly after sqlite_master is used.  They renamed sqlite_master to sqlite_schema, but both exist at this point and will for the foreseeable future.
@mphill mphill merged commit bb068eb into master Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant