Skip to content

getTableNames and logTableNames return alphabetically sorted strings #1030

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

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/class/SimpleDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export default class SimpleDB extends Simple {
}

/**
* Returns an array of all table names in the database.
* Returns an array of all table names in the database, sorted alphabetically.
*
* @returns A promise that resolves to an array of table names.
* @category Table Management
Expand All @@ -456,7 +456,7 @@ export default class SimpleDB extends Simple {
}

/**
* Logs the names of all tables in the database to the console.
* Logs the names of all tables in the database to the console, sorted alphabetically.
*
* @returns A promise that resolves when the table names have been logged.
* @category Table Management
Expand Down
2 changes: 1 addition & 1 deletion src/methods/getTableNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export default async function getTableNames(simpleDB: SimpleDB) {

const tables = queryResult.map((d) => d.name) as string[];

return tables;
return tables.sort();
}
5 changes: 3 additions & 2 deletions test/unit/class/SimpleDB.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ Deno.test("should run a custom query and return the result", async () => {

Deno.test("should create tables without names", async () => {
const sdb = new SimpleDB();
const table1 = sdb.newTable();
// Table 2 first to make sure results are sorted alphabetically
const table1 = sdb.newTable("table2");
await table1.loadData(["test/data/files/data.json"]);
const table2 = sdb.newTable();
const table2 = sdb.newTable("table1");
await table2.loadData(["test/data/files/data.json"]);

const tables = await sdb.getTableNames();
Expand Down