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

notion-db-js

v1.0.41

Published

A Notion database wrapper for easier querying

Downloads

80

Readme

notion-db-js

⚠️ Warning: Package Under Development

This package is currently in the development stage. Some features are limited or not yet implemented. It is not recommended for use in production environments.


notion-db-js is a JavaScript/TypeScript library designed to simplify interactions with Notion databases. This library abstracts the complexities of directly dealing with the Notion API, allowing for easier database operations.

Current Implementation Status

✅ Implemented:

  • Basic initialization
  • Insert records (insert())
  • Full record selection (select())

⏳ Not Yet Implemented:

  • Column-specific selection
  • Update operations
  • Delete operations
  • Filtering
  • Sorting
  • Pagination
  • Full TypeScript support

Installation

npm install notion-db-js

Basic Usage

Initialization

import NotionDB from "notion-db-js";

// Recommended: Create a singleton instance
let notionDB: NotionDB | null = null;

async function initializeNotionDB() {
  if (!notionDB) {
    notionDB = new NotionDB(process.env.NOTION_INTEGRATION_TOKEN as string);
    await notionDB.initialize();
  }
  return notionDB;
}

Fetching All Records

const db = await initializeNotionDB();
const { data, error } = await db.from("your-database-name").select();

if (error) {
  console.error("Error fetching data:", error);
} else {
  console.log("Fetched data:", data);
}

Creating a Record

const db = await initializeNotionDB();
const newRecordId = await db.from("your-database-name").insert({
  title: "New Record",
  description: "This is a new record",
  status: "active",
});

Next.js Integration Example

Here's a real-world example of using notion-db-js in a Next.js API route:

// app/api/notion/db/route.ts
import { NextRequest, NextResponse } from "next/server";
import NotionDB from "notion-db-js";

let notionDB: NotionDB | null = null;

async function initializeNotionDB() {
  if (!notionDB) {
    notionDB = new NotionDB(process.env.NOTION_INTEGRATION_TOKEN as string);
    await notionDB.initialize();
  }
  return notionDB;
}

export async function POST(req: NextRequest) {
  const body = await req.json();

  try {
    const db = await initializeNotionDB();

    const { blogName, domain, email, template } = body;
    await db.from("notion-press-db").insert({
      blogName,
      domain,
      email,
      template,
    });

    return NextResponse.json(
      { success: true, message: "Databases initialized successfully" },
      { status: 200 }
    );
  } catch (error) {
    console.error(error);
    return NextResponse.json({
      message: "NotionDBへの保存に失敗しました。",
    });
  }
}

Using this code, you can save data to your Notion database as shown in the image below:

Notion Database

Architecture Overview

The diagram above illustrates how notion-db-js acts as a bridge between your Next.js application and the Notion API, simplifying database operations.

Known Limitations

  • Currently only supports full table selection (no column-specific selection)
  • Update and delete operations are not yet implemented
  • TypeScript support is limited
  • No filtering or sorting capabilities yet
  • Basic error handling only

Contributing

Bug reports and feature requests are welcome on GitHub Issues. Pull requests are also welcome.

License

This project is released under the MIT License. See the LICENSE file for details.

Author

ShinCode


If you have any questions or need support, please open an issue on GitHub Issues.