Skip to content

Commit 4c0e148

Browse files
committed
feat: enhance resource creation with searchable table selection and fix primary key detection in Clickhouse connector
1 parent 33a2413 commit 4c0e148

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

adminforth/commands/createResource/main.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { callTsProxy, findAdminInstance } from "../callTsProxy.js";
22
import { toTitleCase } from '../utils.js';
33
import { generateResourceFile } from "./generateResourceFile.js";
44
import { injectResourceIntoIndex } from "./injectResourceIntoIndex.js";
5-
import { select } from "@inquirer/prompts";
5+
import { search, Separator } from "@inquirer/prompts";
66

77
export default async function createResource(args) {
88
console.log("Bundling admin SPA...");
@@ -27,9 +27,20 @@ export default async function createResource(args) {
2727
}))
2828
);
2929

30-
const table = await select({
31-
message: "🗂 Choose a table to generate a resource for:",
32-
choices: tableChoices,
30+
const table = await search({
31+
message: '🔍 Choose a table to generate a resource for:',
32+
source: async (input = '') => {
33+
const term = input.toLowerCase();
34+
const choices = tableChoices
35+
.filter(c =>
36+
c.name.toLowerCase().includes(term)
37+
)
38+
.map(c => ({ name: c.name, value: c.value }));
39+
return [
40+
...choices,
41+
new Separator(),
42+
];
43+
},
3344
});
3445

3546
const columns = await callTsProxy(`

adminforth/dataConnectors/clickhouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
108108
field._underlineType = baseType;
109109
field._baseTypeDebug = baseType;
110110
field.required = row.notnull == 1;
111-
field.primaryKey = row.pk == 1;
111+
field.primaryKey = row.is_in_primary_key == 1;
112112
field.default = row.dflt_value;
113113
fieldTypes[row.name] = field
114114
});

adminforth/dataConnectors/mongo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
5656

5757
async getAllColumnsInTable(collectionName: string): Promise<Array<string>> {
5858

59-
const sampleDocs = await this.client.db().collection(collectionName).find({}).limit(100).toArray();
59+
const sampleDocs = await this.client.db().collection(collectionName).find({}).sort({ _id: -1 }).limit(100).toArray();
6060

6161
const fieldSet = new Set<string>();
6262

0 commit comments

Comments
 (0)