Skip to main content
Glama
get-primary-key.ts702 B
/** * Gets the primary key field name for a specified collection * @param collection The collection name to get the primary key for * @param schema The collections schema object containing field definitions * @returns The name of the primary key field or null if not found */ export function getPrimaryKeyField( collection: string, schema: Record<string, Record<string, any>>, ): string | null { // Check if collection exists in schema if (!schema[collection]) { return null; } // Find the field that has primary_key: true for (const [fieldName, fieldConfig] of Object.entries(schema[collection])) { if (fieldConfig.primary_key === true) { return fieldName; } } return null; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JoshTheDerf/directus-extension-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server