Skip to content

Commit

Permalink
Refactor addDatabaseEntry to handle multiple database tables and expo…
Browse files Browse the repository at this point in the history
…rt additional functions and types
  • Loading branch information
Adammatthiesen committed Dec 10, 2024
1 parent ebf5687 commit 59e52af
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
26 changes: 22 additions & 4 deletions packages/studiocms_core/src/sdk-utils/add/addDatabaseEntry.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/// <reference types="@astrojs/db" />
import { db } from 'astro:db';
import { tsPageContent, tsPageData } from '../../db/tsTables';
import type { addDatabaseEntryInsertPage, tsPageContentInsert, tsPageDataInsert } from '../types';
import type {
addDatabaseEntryDatabase,
addDatabaseEntryInsertPage,
tsPageContentInsert,
tsPageDataInsert,
} from '../types';

/**
* Adds a new entry to the specified database table.
*/
export function addDatabaseEntry(
database: 'pages' | 'pageContent' | 'tags' | 'categories' | 'permissions'
) {
export function addDatabaseEntry(database: addDatabaseEntryDatabase) {
switch (database) {
case 'pages': {
return {
Expand Down Expand Up @@ -90,6 +93,21 @@ export function addDatabaseEntry(
},
};
}
case 'tags': {
return {
insert: async () => {},
};
}
case 'categories': {
return {
insert: async () => {},
};
}
case 'permissions': {
return {
insert: async () => {},
};
}
default: {
throw new Error('Invalid database entry');
}
Expand Down
16 changes: 16 additions & 0 deletions packages/studiocms_core/src/sdk-utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ export type addDatabaseEntryInsertPage = {
pageContent: PageContentReturnId[];
};

/**
* Represents the possible database entries that can be added.
*
* @property {'pages'} pages - Represents the pages database entry.
* @property {'pageContent'} pageContent - Represents the page content database entry.
* @property {'tags'} tags - Represents the tags database entry.
* @property {'categories'} categories - Represents the categories database entry.
* @property {'permissions'} permissions - Represents the permissions database entry.
*/
export type addDatabaseEntryDatabase =
| 'pages'
| 'pageContent'
| 'tags'
| 'categories'
| 'permissions';

/**
* Interface for retrieving user data from the database.
* Provides methods to fetch user data by different identifiers.
Expand Down

0 comments on commit 59e52af

Please sign in to comment.