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

jinaga-export-postgres

v1.0.0

Published

CLI tool to export data from Jinaga PostgreSQL database

Downloads

3

Readme

jinaga-export-postgres

A command-line tool to export data from a Jinaga PostgreSQL database.

Installation

This package can be used directly via npx without installation, or you can install it globally using npm:

npm install -g jinaga-export-postgres

Usage

To use the tool, run the following command:

npx jinaga-export-postgres --host <host> --port <port> --database <database> --user <user> --password <password> --format <format>

Replace the placeholders with your PostgreSQL database details:

  • <host>: The hostname of your PostgreSQL server
  • <port>: The port number of your PostgreSQL server
  • <database>: The name of your Jinaga database
  • <user>: The username for accessing the database
  • <password>: The password for the specified user
  • <format>: The output format. Must be either 'json' or 'factual'

Example:

npx jinaga-export-postgres --host localhost --port 5432 --database myjinagarecords --user myuser --password mypassword --format json

The tool will connect to the specified PostgreSQL database, check for the existence of the 'fact' table, and if it exists, export all facts from the table in the specified format.

Output Formats

The exported data is streamed to stdout in either JSON or Factual format, depending on the --format option.

JSON Format

When using the JSON format (--format json), the output is an array of fact objects, where each fact object has the following structure:

{
  "hash": "string",
  "type": "string",
  "predecessors": {
    "single": {
      "hash": "string",
      "type": "string"
    },
    "multiple": [
      {
        "hash": "string",
        "type": "string"
      },
      {
        "hash": "string",
        "type": "string"
      }
    ]
  },
  "fields": {
    "key": "value"
  }
}
  • hash: A unique identifier for the fact
  • type: The type of the fact
  • predecessors: An object containing references to predecessor facts
    • Each key in the object may contain either a single predecessor or an array of multiple predecessors
  • fields: An object containing the fact's data fields

Factual Format

When using the Factual format (--format factual), the output is a series of JavaScript-like fact declarations. Each fact is represented as follows:

let f<fact_id>: <fact_type> = {
    <field_key>: <field_value>,
    ...
    <predecessor_key>: f<predecessor_fact_id>,
    <predecessor_array_key>: [f<predecessor_fact_id1>, f<predecessor_fact_id2>, ...],
    ...
}
  • <fact_id>: A unique identifier for the fact
  • <fact_type>: The type of the fact
  • <field_key> and <field_value>: The fact's data fields
  • <predecessor_key> and <predecessor_fact_id>: References to single predecessor facts
  • <predecessor_array_key>: References to arrays of predecessor facts

Example of Factual format output:

let f1: Blog.Site = {
    domain: "example.com"
}

let f2: Blog.Post = {
    createdAt: "2023-05-20T10:30:00Z",
    site: f1
}

let f3: Blog.Post.Title = {
    post: f2,
    value: "My First Blog Post",
    prior: []
}

Working with the Output

Writing to a File

To save the output to a file, you can use output redirection:

For JSON format:

npx jinaga-export-postgres --host localhost --port 5432 --database mydb --user myuser --password mypassword --format json > output.json

For Factual format:

npx jinaga-export-postgres --host localhost --port 5432 --database mydb --user myuser --password mypassword --format factual > output.fact

Using jq for Processing (JSON format only)

jq is a lightweight command-line JSON processor. You can pipe the output of jinaga-export-postgres to jq for further processing or formatting when using the JSON format:

  1. Pretty-print the JSON:

    npx jinaga-export-postgres ... --format json | jq '.'
  2. Count the number of facts:

    npx jinaga-export-postgres ... --format json | jq 'length'
  3. Filter facts by type:

    npx jinaga-export-postgres ... --format json | jq '[.[] | select(.type == "YourFactType")]'
  4. Find a fact by hash:

    npx jinaga-export-postgres ... --format json | jq '.[] | select(.hash == "YourFactHash")'
  5. Extract specific fields:

    npx jinaga-export-postgres ... --format json | jq '[.[] | {hash: .hash, type: .type}]'

Remember to install jq (sudo apt-get install jq on Ubuntu or brew install jq on macOS) before using these commands.

Development

If you want to contribute to this project or modify it for your own use, follow these steps:

  1. Clone the repository:

    git clone https://github.com/yourusername/jinaga-export-postgres.git
    cd jinaga-export-postgres
  2. Install dependencies:

    npm install
  3. Make your changes in the src/index.ts file.

  4. Build the project:

    npm run build
  5. Test your changes locally:

    node dist/index.js --host localhost --port 5432 --database mydb --user myuser --password mypassword --format json
  6. If everything works correctly, update the version number in package.json and publish the package to npm:

    npm publish

Project Structure

  • src/index.ts: The main source file containing the CLI tool logic
  • dist/: The output directory for compiled JavaScript files
  • package.json: Project configuration and dependencies
  • tsconfig.json: TypeScript compiler configuration

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Requirements

  • Node.js version 14.0.0 or higher
  • Access to a PostgreSQL database used by Jinaga

Support

If you encounter any problems or have any questions, please open an issue in the GitHub repository.