feat: initial pagination
This commit is contained in:
10
client/composables/editor.ts
Normal file
10
client/composables/editor.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { useClipboard } from '@vueuse/core'
|
||||||
|
|
||||||
|
export function useCopy() {
|
||||||
|
const clipboard = useClipboard()
|
||||||
|
|
||||||
|
return (text: string) => {
|
||||||
|
clipboard.copy(text)
|
||||||
|
// TODO: show toast
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,8 +26,15 @@ export function setupDatabaseRPC({ options }: NuxtDevtoolsServerContext): any {
|
|||||||
const { _id, ...rest } = data
|
const { _id, ...rest } = data
|
||||||
return await mongoose.connection.db.collection(collection).insertOne(rest)
|
return await mongoose.connection.db.collection(collection).insertOne(rest)
|
||||||
},
|
},
|
||||||
async listDocuments(collection: string) {
|
async countDocuments(collection: string) {
|
||||||
return await mongoose.connection.db.collection(collection).find().toArray()
|
return await mongoose.connection.db.collection(collection).countDocuments()
|
||||||
|
},
|
||||||
|
async listDocuments(collection: string, options: { page: number; limit: number } = { page: 1, limit: 10 }) {
|
||||||
|
const skip = (options.page - 1) * options.limit
|
||||||
|
const cursor = mongoose.connection.db.collection(collection).find().skip(skip)
|
||||||
|
if (options.limit !== 0)
|
||||||
|
cursor.limit(options.limit)
|
||||||
|
return await cursor.toArray()
|
||||||
},
|
},
|
||||||
async getDocument(collection: string, document: {}) {
|
async getDocument(collection: string, document: {}) {
|
||||||
return await mongoose.connection.db.collection(collection).findOne({ document })
|
return await mongoose.connection.db.collection(collection).findOne({ document })
|
||||||
|
|||||||
@ -8,7 +8,8 @@ export interface ServerFunctions {
|
|||||||
|
|
||||||
// Database - documents
|
// Database - documents
|
||||||
createDocument(collection: string, data: any): Promise<any>
|
createDocument(collection: string, data: any): Promise<any>
|
||||||
listDocuments(collection: string): Promise<any>
|
countDocuments(collection: string): Promise<any>
|
||||||
|
listDocuments(collection: string, options: any): Promise<any>
|
||||||
getDocument(collection: string, id: string): Promise<any>
|
getDocument(collection: string, id: string): Promise<any>
|
||||||
updateDocument(collection: string, data: any): Promise<any>
|
updateDocument(collection: string, data: any): Promise<any>
|
||||||
deleteDocument(collection: string, id: string): Promise<any>
|
deleteDocument(collection: string, id: string): Promise<any>
|
||||||
|
|||||||
Reference in New Issue
Block a user