-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
138 additions
and
61 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
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,49 @@ | ||
|
||
|
||
# TypeScript | ||
|
||
## Configuration | ||
Set `moduleResolution` in the `compilerOptions` in your `tsconfig.json` to be either `Node16` or `NodeNext`. | ||
|
||
When importing types, always refer to the standard orama import: | ||
|
||
```ts copy | ||
import type { Language } from '@orama/orama' | ||
``` | ||
|
||
## Usage | ||
|
||
Orama is written in TypeScript and provides type definitions for all of its public APIs. | ||
This means the results of all functions are typed, and the types are **inferred from the schema provided**. | ||
|
||
```typescript copy | ||
const db = await create({ | ||
schema: { | ||
title: 'string', | ||
plot: 'string', | ||
} | ||
}) | ||
await insert(db, { | ||
title: 'The prestige', | ||
plot: 'Two friends and fellow magicians become bitter enemies after a sudden tragedy. As they devote themselves to this rivalry, they make sacrifices that bring them fame but with terrible consequences.' | ||
}) | ||
const s = await search(db, { term: 'prestige' }) | ||
|
||
const firstTitle: string = s.hits[0].document.title // Inferred by the schema provided | ||
``` | ||
|
||
Anyway, because Orama schema defines only searchable fields, you may want to add some extra fields to your documents. | ||
Extra fields are not indexed, so they are not searchable, but they are still available in the results. | ||
The type of these fields is not inferred, so it's `any`. | ||
|
||
```typescript copy | ||
await insert(db, { | ||
title: 'Big Fish', | ||
director: 'Tim Burton', | ||
plot: 'Will Bloom returns home to care for his dying father, who had a penchant for telling unbelievable stories. After he passes away, Will tries to find out if his tales were really true.', | ||
year: 2004, | ||
isFavorite: true | ||
}) | ||
const s = await search(db, { term: 'fish' }) | ||
const year: any = s.hits[0].document.year // not inferred, so it's any | ||
``` |