@tigrisdata/astro
v1.0.0
Published
An Astro integration that enables accessing a Tigris NoSQL database
Downloads
4
Readme
Tigris Astro Integration
💡 What is Tigris?
If you are first-time user of Tigris, read the Getting Started guide to cover the basics.
🔨 Installation
Install @tigrisdata/astro
:
npm install @tigrisdata/astro
# yarn add @tigrisdata/astro
Add the following code to astro.config.mjs
and replace the YOUR_TIGRIS_PROJECT_NAME
, YOUR_TIGRIS_CLIENT_ID
, and YOUR_TIGRIS_CLIENT_SECRET
with the values from your Tigris project.
import { defineConfig } from "astro/config";
import tigris from "@tigrisdata/astro";
export default defineConfig({
integrations: [
tigris({
branch: "main",
projectName: "YOUR_TIGRIS_PROJECT_NAME",
clientId: "YOUR_TIGRIS_CLIENT_ID",
clientSecret: "YOUR_TIGRIS_CLIENT_SECRET",
}),
],
});
Options
When you initialize the integration, you can pass all @tigrisdata/core options.
🚀 Getting Started
Tigris collections are available with the useTigrisCollection
hook:
import { useTigrisCollection } from "@tigrisdata/astro";
Fetching All Documents
You can fetch (and filter) all documents from a collection using the findMany
method:
---
import { useTigrisCollection } from "@tigrisdata/astro";
import { User } from "./types/User";
const userCollection = await useTigrisCollection<User>("users");
const usersCursor = await userCollection.findMany({});
const users = await usersCursor.toArray();
---
{users.map(user =>
<div>{user.name}</div>
)}
Fetching One Document
You can fetch one document from a collection using the findOne
method:
---
import { useTigrisCollection } from "@tigrisdata/astro";
import { User } from "./types/User";
const userCollection = await useTigrisCollection<User>("users");
const user = await userCollection.findOne({
filter: {
id: "1234"
}
});
---
<div>{user.name}</div>
👀 Want to learn more?
Feel free to check our documentation or jump into our Discord server.