Skip to content

Commit

Permalink
feat(repository): in memory respository implement find one
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenqin Nee authored and Chenqin Nee committed Dec 14, 2022
1 parent cf4095d commit 0cc565e
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IQueryRecordSchema, IRecordQueryModel, IRecordSpec, QueryRecords } from '@egodb/core'
import { WithRecordIdS } from '@egodb/core'
import type { Option } from 'oxide.ts'
import { Option } from 'oxide.ts'
import { db } from '../db'
import { RecordInMemoryQueryVisitor } from './record-in-memory.query-visitor'

Expand All @@ -13,7 +13,11 @@ export class RecordInMemoryQueryModel implements IRecordQueryModel {
}

async findOne(spec: IRecordSpec): Promise<Option<IQueryRecordSchema>> {
throw new Error('unimplemented')
const visitor = new RecordInMemoryQueryVisitor()
spec.accept(visitor).unwrap()

const found = db.data?.records.find(visitor.getPredicate().unwrap())
return Option(found)
}

findOneById(id: string): Promise<Option<IQueryRecordSchema>> {
Expand Down

0 comments on commit 0cc565e

Please sign in to comment.