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

simplistik

v0.2.7

Published

bootstrap a graphql/knex DB as fast as possible

Downloads

2

Readme

Simplistik

Getting Started

This tutorial will show how to use simplistik with sqlite(dev), postgres(production) on heroku.

$ mkdir dummy-project
$ cd dummy-project
$ yarn init
$ yarn add simplistik-cli pg sqlite3
$ yarn run knex init
$ yarn run simplistik init

Open the project in your editor and let's edit knexfile.js :

// knexfile.js
module.exports = {
  development: {
    client: 'sqlite3',
    connection: {
      filename: './dev.sqlite3',
    },
  },

  production: {
    client: 'pg',
    connection: process.env.DATABASE_URL,
    pool: {
      min: 2,
      max: 10,
    },
    migrations: {
      tableName: 'knex_migrations',
    },
  },
}

The process.env.DATABASE_URL is specific to heroku, you'll need to adapt this part to your configuration and database stack.

Then go to heroku, then :

  • create a new project (or use the heroku cli).
  • add addons:postgres
  • in settings tab, add the config_vars :
    • secret = yoursecret
    • NODE_ENV = production

In the Config Vars you should see the DATABASE_URL from your postgres addons. Don't change it, we will use this value for knexfile.js

Once your heroku app is ready, comeback to your project.

Go to your package.json and add those scripts :

// package.json
[...]
"scripts": {
  "postinstall": "knex migrate:latest",
  "start": "simplistik"
},
[...]

If you're using seeds, change postinstall script to knex migrate:latest && knex seed:run

You are now ready to push your app to heroku, add heroku as a git remote by following the step from heroku Deploy tab and push your app.

git push heroku master

Your app should be uploaded to heroku and start after runnning the migrations.

Before being able to use your graphql api you need to create a user and get an api_key. To create an user use this command : heroku run simplistik new:user -u <username>

The command should create the user in your DB and print an api_key in the console.

Use the graphQL api

The easiest way to test your api is to use GraphiQL App Once the app is open :

  • Change the url to your graphql api "http:///graphql"
  • Authorization : Bearer <api_key>

To test the api, you can use this query :

{
  user(id: "1") {
    username
    id
  }
}

the api should return :

{
  "data": {
    "user": {
      "username": <your username>,
      "id": "1"
    }
  }
}

CLI

init

  • create default db.js
  • create knex default migrations
  • create knex default seeds directory
  • create default graphql types
  • create default graphql resolvers

new:user (--username, -u)

  • create a user and print his api_key

TODO : delete-user (--mail, -m)

  • delete the user from db