-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What problem does this PR solve? feat: Create database #1841 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
- Loading branch information
Showing
8 changed files
with
87 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
'use server'; | ||
|
||
import { deleteProductById } from '@/lib/db'; | ||
import { revalidatePath } from 'next/cache'; | ||
import { ApiUrl } from '@/lib/constant/api'; | ||
import { CreateOption } from '@/lib/constant/common'; | ||
import { get, post } from '@/lib/request'; | ||
|
||
export async function deleteProduct(formData: FormData) { | ||
// let id = Number(formData.get('id')); | ||
// await deleteProductById(id); | ||
// revalidatePath('/'); | ||
} | ||
|
||
export async function createDatabaseAction(formData: FormData) { | ||
// let id = Number(formData.get('id')); | ||
// await deleteProductById(id); | ||
// revalidatePath('/'); | ||
} | ||
|
||
export const createDatabase = async (params: { | ||
database_name: string; | ||
create_option: CreateOption; | ||
}) => { | ||
try { | ||
const x = await post(`${ApiUrl.databases}/${params.database_name}`, { | ||
create_option: params.create_option | ||
}); | ||
console.log('🚀 ~ x:', x); | ||
return x; | ||
} catch (error) { | ||
console.log('🚀 ~ error:', error); | ||
} | ||
}; | ||
|
||
export const listDatabase = async () => { | ||
try { | ||
const x = await get(`${ApiUrl.databases}`); | ||
console.log('🚀 ~ x:', x); | ||
return x; | ||
} catch (error) { | ||
console.log('🚀 ~ error:', error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum CreateOption { | ||
Error = 'error', | ||
IgnoreIfExists = 'ignore_if_exists' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { ApiUrl } from '../constant/api'; | ||
import { CreateOption } from '../constant/common'; | ||
import { post } from '../request'; | ||
|
||
export const createDatabase = async (databaseName: string) => { | ||
return post(`${ApiUrl.databases}/${databaseName}`, { create_option: 'post' }); | ||
export const createDatabase = async ( | ||
databaseName: string, | ||
createOption: CreateOption | ||
) => { | ||
return post(`${ApiUrl.databases}/${databaseName}`, { | ||
create_option: createOption | ||
}); | ||
}; |