mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 23:20:34 +07:00
feat: generate schema from template
This commit is contained in:
35
generation/templates/scheme.tmpl
Normal file
35
generation/templates/scheme.tmpl
Normal file
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import Table from '../table/Table.vue'
|
||||
import { onMounted, reactive } from 'vue'
|
||||
import { getDefaultValues } from '../utils/structs/defaults.util'
|
||||
import Service from './{{.LowerName}}.service.ts'
|
||||
import type { Scheme } from '../types/scheme.type'
|
||||
import { {{.StructName}} } from '{{.GolangServicesPath}}'
|
||||
{{range .Dependencies}}
|
||||
import {{.ImportName}} from '../{{.LowerName}}/{{.LowerName}}.service.ts'
|
||||
const {{.ServiceName}} = new {{.ImportName}}
|
||||
{{end}}
|
||||
|
||||
const service = new Service
|
||||
|
||||
onMounted(async () => {
|
||||
{{range .Dependencies}}
|
||||
(scheme as any).{{.FieldName}}.type!.nested!.values = await {{.ServiceName}}.readAll()
|
||||
{{end}}
|
||||
})
|
||||
|
||||
const scheme: Scheme<{{.StructName}}> = reactive({
|
||||
{{range .Fields}}
|
||||
{{.Name}}: {{.Generate}},
|
||||
{{end}}
|
||||
})
|
||||
|
||||
const getDefaults = () => getDefaultValues(scheme)
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="w-screen h-screen">
|
||||
<Table :scheme :service :getDefaults></Table>
|
||||
</main>
|
||||
</template>
|
||||
27
generation/templates/service.tmpl
Normal file
27
generation/templates/service.tmpl
Normal file
@@ -0,0 +1,27 @@
|
||||
import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/authorservice.ts"
|
||||
import type { Author } from "../../bindings/app/internal/services/models.ts"
|
||||
import type { IService } from "../types/service.type.ts"
|
||||
|
||||
export default class AuthorService implements IService<Author> {
|
||||
async read(id: number) {
|
||||
return await GetById(id)
|
||||
}
|
||||
|
||||
async readAll() {
|
||||
return await GetAll() as Author[]
|
||||
}
|
||||
|
||||
async create(item: Author) {
|
||||
await Create(item)
|
||||
}
|
||||
|
||||
async delete(id: number) {
|
||||
return await Delete(id)
|
||||
}
|
||||
async update(item: Author) {
|
||||
await Update(item)
|
||||
}
|
||||
async count() {
|
||||
return await Count()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user