Skip to content

Commit

Permalink
feat: update db logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bbtgnn committed Mar 7, 2024
1 parent da2acfd commit 2376081
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/__cms/dao/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ export function create<C extends CollectionName>(
export function get_document<C extends CollectionName>(
collection_name: C,
document_name: DocumentName<C>
): Document<C> | Error {
): Document<C> | undefined {
return pipe(
Effect.all([
get_base_document(`${collection_name}/${document_name}`),
get_collection_schema(collection_name)
]),
Effect.flatMap(([base_document, schema]) => parse_base_document(base_document, schema)),
Effect.catchAll((e) => Effect.succeed(e)),
Effect.catchAll(() => Effect.succeed(undefined)),
Effect.runSync
);
}
Expand All @@ -80,6 +80,13 @@ export function get_collection<C extends CollectionName>(
]),
Effect.flatMap(([documents, schema]) => parse_base_documents(documents, schema)),
Effect.map((documents) => sort_documents(documents, options.sort)),
Effect.match({
onFailure: (e) => {
console.log(e);
return [];
},
onSuccess: (a) => a
}),
Effect.runSync
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/__cms/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Type as T, type StaticDecode } from '@sinclair/typebox';
import { database_index, database_index_schema } from './database_index';
import type { CollectionName } from './database';

import { db } from '.';
import { get_document } from '.';

//

Expand Down Expand Up @@ -72,7 +72,7 @@ export function Relation<C extends CollectionName>(collection_name: C) {
.Decode((document) => ({
collection: collection_name,
document,
get: () => db.get_document(collection_name, document)
get: () => get_document(collection_name, document)
}))
.Encode((field) => field.document);
}
Expand Down
3 changes: 3 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<script lang="ts">
</script>

Home page

0 comments on commit 2376081

Please sign in to comment.