-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from CRBroughton/63-offer-limited-select-state…
…ments-instead-of-performing-select-for-every-select-all-query feat: ✨ Implement limited search
- Loading branch information
Showing
21 changed files
with
489 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@crbroughton/sibyl": minor | ||
--- | ||
|
||
Implement limited search - The Select function now support limited queries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-disable unused-imports/no-unused-vars */ | ||
import { describe, expect, it } from 'bun:test' | ||
import { Database } from 'bun:sqlite' | ||
import type { Equals, Expect } from '@crbroughton/ts-test-utils' | ||
import Sibyl from '../index' | ||
import type { SibylResponse } from '../../types' | ||
|
||
interface firstTable { | ||
id: number | ||
name: string | ||
location: string | ||
hasReadTheReadme: boolean | ||
} | ||
interface Tables { | ||
firstTable: firstTable | ||
} | ||
|
||
describe('LimitedSelect tests', () => { | ||
it('selects an entry from the DB, using the limited functionality', async () => { | ||
const db = new Database(':memory:') | ||
const { createTable, Insert, LimitedSelect } = await Sibyl<Tables>(db) | ||
|
||
createTable('firstTable', { | ||
id: { | ||
autoincrement: true, | ||
type: 'INTEGER', | ||
primary: true, | ||
unique: true, | ||
}, | ||
name: { | ||
type: 'char', | ||
size: 10, | ||
}, | ||
hasReadTheReadme: { | ||
type: 'bool', | ||
}, | ||
location: { | ||
type: 'char', | ||
size: 10, | ||
}, | ||
}) | ||
|
||
Insert('firstTable', [ | ||
{ | ||
id: 1, | ||
hasReadTheReadme: true, | ||
location: 'Brighton', | ||
name: 'Craig', | ||
}, | ||
{ | ||
id: 2, | ||
hasReadTheReadme: false, | ||
location: 'Leeds', | ||
name: 'Bob', | ||
}, | ||
{ | ||
id: 3, | ||
hasReadTheReadme: true, | ||
location: 'Brighton', | ||
name: 'David', | ||
}, | ||
]) | ||
|
||
const actual = LimitedSelect('firstTable', { | ||
where: { | ||
name: 'Craig', | ||
hasReadTheReadme: 1, | ||
}, | ||
}) | ||
|
||
// Type tests | ||
const singluarActual = actual![0] | ||
type ActualType = typeof singluarActual | ||
type ExpectedType = Omit<SibylResponse<firstTable>, 'id' | 'location'> | ||
type ResultType = Expect<Equals<ActualType, ExpectedType>> | ||
// ^? | ||
|
||
const expectation: ExpectedType[] = [ | ||
{ | ||
hasReadTheReadme: 1, | ||
name: 'Craig', | ||
}, | ||
] | ||
expect(actual).toStrictEqual(expectation) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.