|
- import { resource, application, validation as v } from '@modal-sh/yasumi';
- import { http } from '@modal-sh/yasumi/backend';
- import { DuckDbDataSource, AutoincrementIdConfig } from '@modal-sh/yasumi-data-source-duckdb';
- import { constants } from 'http2';
-
- const Post = resource(
- v.object({
- title: v.string(),
- content: v.string(),
- })
- )
- .name('Post')
- .route('posts')
- .id('id', AutoincrementIdConfig)
- .createdAt('createdAt')
- .updatedAt('updatedAt')
- .canFetchItem()
- .canFetchCollection()
- .canCreate()
- .canEmplace()
- .canPatch()
- .canDelete();
-
- const app = application({
- name: 'duckdb-service'
- })
- .resource(Post);
-
- const backend = app.createBackend({
- dataSource: new DuckDbDataSource('test.db'),
- })
- .showTotalItemCountOnGetCollection()
- .throwsErrorOnDeletingNotFound();
-
- const server = backend.createHttpServer({
- basePath: '/api',
- })
- .defaultErrorHandler((_req, res) => () => {
- throw new http.ErrorPlainResponse('urlNotFound', {
- statusCode: constants.HTTP_STATUS_NOT_FOUND,
- res,
- });
- // throw new http.ErrorPlainResponse('notImplemented', {
- // statusCode: constants.HTTP_STATUS_NOT_IMPLEMENTED,
- // res,
- // });
- });
-
- server.listen(6969);
|