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

ass-mongoose

v1.0.1

Published

A Mongoose StorageEngine for ass (a ShareX Server)

Downloads

4

Readme

ass-mongoose

A Mongoose StorageEngine for ass (a ShareX Server)

Usage

  1. Install with npm i ass-mongoose
  2. Create a config.mongoose.json file in the root of your project with the following content:
    {
      "host": "domain.of.mongoose.database",
      "port": 12345,
      "database": "your-db-name",
      "mongooseOpts": {
        "useNewUrlParser": true,
        "useUnifiedTopology": true,
        ...,
      },
      "model": "your-imported-model-name"
    }

| Key | Description | | --- | --- | | host | Hostname of the server | | port | Port of the server | | database | Name of the database | | mongooseOpts | An object of Mongoose options | | model | The model of the data schema |

  1. Add ass-mongoose to data.js using require & create a new instance of MongooseStorageEngine:
// Import the package
const { MongooseStorageEngine } = require('ass-mongoose');

// Import the options
const { host, port, database, mongooseOpts, model } = require('./config.mongoose.json');

// Create a new instance of the MongooseStorageEngine
const data = new MongooseStorageEngine({
  host, 
  port, 
  database,
  mongooseOpts,
  model, 
});

// Initialize the StorageEngine
// Always call data.init() before using the StorageEngine!
data.init()
  .then(console.log)
  .catch(console.error);

// Export the StorageEngine
module.exports = data;

The init() method

The init() method is used to initialize the StorageEngine. It returns a Promise that resolves when the StorageEngine is ready to use.

This method is used to create the database if it doesn't already exist.

Migrating old data (from JsonStorageEngine)

Create a new instance of MongooseStorageEngine with the same options as before. Run data.migrate(), which returns a Promise. The result of .then() is the number of data entries migrated.

// Import the old StorageEngine
const { JsonStorageEngine } = require('@tycrek/ass-storage-engine');
const dataOld = new JsonStorageEngine();

// Import the new StorageEngine & options
const { MongooseStorageEngine } = require('ass-mongoose');
const { host, port, database, mongooseOpts, model } = require('./config.mongoose.json');

// Create a new instance of the MongooseStorageEngine
const data = new MongooseStorageEngine({ /* ... */ });
data.init()
  .then(console.log)
  .then(() => dataOld.get())
  .then((oldData) => data.migrate(oldData)) // <-- Remove this after migration!
  .then(console.log)
  .catch(console.error);

module.exports = data;

Only run this command if you are sure you want to migrate your data!

Make sure you have a backup of your data before running this command. In pretty much all scenarios, you'll only need to run this command once, and then you can remove the migrate function from your code. Calling data.migrate() will only work if you have a data.json file in your project root. It will not modify or delete your data.json file (but having a backup of your data is still a good idea)

Delete your table

If you want to delete the entire table, with zero data returns or backups or anything, you can use the following code:

// Please realize this is dangerous
data.deleteTable()
  .then(console.log)
  .catch(console.error);
// There is no undo for this command!

This will immediatly delete your table, use with caution! The table will automatically be created when you call data.init() again.