0.1.1 • Published 10 months ago

@harperdb/nestjs v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@harperdb/nestjs

A HarperDB Component for running and developing NestJS apps.

NPM Version

Most Next.js features are supported as we rely on the NestJS Server provided by NestJS to run your application.

Usage

!NOTE This guide assumes you're already familiar with HarperDb Components. Please review the documentation, or check out the HarperDB Next.js Example for more information.

  1. Install:
npm install @harperdb/nestjs
  1. Add to config.yaml:
'@harperdb/nestjs':
  package: '@harperdb/nestjs'
  files: '/*'
  1. Run your app with HarperDB:
harperdb run nestjs-app
  1. Within any server side code paths, you can use HarperDB Globals after importing the HarperDB package:
// app/actions.js
'use server';

import('harperdb');

export async function listDogs() {
	const dogs = [];
	for await (const dog of tables.Dog.search()) {
		dogs.push({ id: dog.id, name: dog.name });
	}
	return dogs;
}

export async function getDog(id) {
	return tables.Dog.get(id);
}
// app/dogs/[id]/page.jsx
import { getDog, listDogs } from '@/app/actions';

export async function generateStaticParams() {
	const dogs = await listDogs();

	return dogs;
}

export default async function Dog({ params }) {
	const dog = await getDog(params.id);

	return (
		<section>
			<h1>{dog.name}</h1>
			<p>Breed: {dog.get('breed')}</p>
			<p>Woof!</p>
		</section>
	);
}
0.1.1

10 months ago

0.1.0

10 months ago