npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-source-serverless-aurora

v0.0.2

Published

A Gatsby source plugin for pulling data into Gatsby at build time from an AWS Serverless Aurora database.

Downloads

3

Readme

gatsby-source-serverless-aurora

A Gatsby source plugin for pulling data into Gatsby at build time from an AWS Serverless Aurora database.

Quick Start

Install the plugin:

npm install --save-dev gatsby-source-serverless-aurora

Add the plugin to gatsby-config.js with your Serverless Aurora connection details and any queries you want to perform.

module.exports = {
	//... your config here
	plugins: [
		{
			resolve: `gatsby-source-serverless-aurora`,
			options: {
				connection: {
					accessKeyId: process.env.AWS_ACCESS_KEY_ID,
					secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
					region: process.env.AWS_REGION,
					resourceArn: process.env.AURORA_RESOURCE_ARN,
					secretArn: process.env.AURORA_SECRET_ARN,
					databaseName: process.env.AURORA_DB_NAME,
				},
				queries: [
					{
						nodeName: `page`,
						statement: `SELECT * FROM pages`,
						idFieldName: `page_id`,
					},
				],
			},
		},
	],
};

Re/start your development server with gatsby develop, open GraphiQL and query it like this:

{
	allServerlessAuroraPage {
		edges {
			node {
				id
				type
				row {
					page_id
					title
				}
			}
		}
	}
}

Plugin Options

These are all the options you can pass to the plugin:

| Option | Required | Default | Description | | -------------------------- | -------- | ------- | -------------------------------------------------------------------------------------------- | | connection.accessKeyId | Required | | An AWS access key ID. | | connection.secretAccessKey | Required | | An AWS secret access key. | | connection.region | Required | | The region for your Serverless Aurora instance. | | connection.resourceArn | Required | | The Resource ARN for your Serverless Aurora instance. | | connection.secretArn | Required | | The Secret ARN for your Serverless Aurora instance. | | connection.databaseName | Required | | The name of the database to use for queries. Can be overridden in each query. | | queryBatchSize | | 10 | The maximum number of simultaneous queries to perform. | | queries[].nodeName | Required | | Gives a name to the nodes created by the query, e.g. "page". | | queries[].statement | Required | | The query to perform. | | queries[].idFieldName | | "id" | The column to use for the unique ID of the Gatsby nodes. | | queries[].databaseName | | | Optionally query a different database for this query only. | | queries[].parentNodeName | | | Optionally link nodes created by this query as children of node(s) created by another query. | | queries[].parentMatcher | | | Optionally filter the parent nodes found with parentNodeName. See below for usage. |

Parent-Child Relationships

Parent-child relationships can easily be created between different nodes. Parents can have as many children as they like, and children can have as many parents as they like.

Example

  • You have a query "page" to return pages: SELECT * FROM pages.
  • You have a query "post" to return posts: SELECT * FROM posts.
  • For the post query you specify the parentNodeName as "page".
  • For the post query you specify the parentMatcher() function to match the page_id of the post to the page_id of the page.
  • Use the links.children.posts[] property to access the posts owned by a page node.
  • Use the links.parents.pages[] property to access the pages a post node belongs to.
queries: [
	{
		nodeName: `page`,
		statement: `SELECT * FROM pages`,
		idFieldName: `page_id`,
	},
	{
		nodeName: `post`,
		statement: `SELECT * FROM posts`,
		idFieldName: `post_id`,
		parentNodeName: `post`,
		parentMatcher: (post, page) => post.page_id === page.page_id,
	},
],

Query it like:

{
	allServerlessAuroraPage {
		edges {
			node {
				id
				type
				row {
					page_id
					title
				}
				links {
					children {
						posts {
							id
							row {
								post_id
								title
							}
						}
					}
				}
			}
		}
	}
}

parentMatcher(child, parent) => boolean

The parentMatcher function is passed two nodes, child and parent. It must return true if the child should be linked to the parent, otherwise false.

The child parameter will be a node returned by the current query, and the parent parameter will be a node with a name that matches the parentNodeName option if specified (or all nodes returned by all queries if not).