@truffle/db-loader

Utility for loading @truffle/db

Usage no npm install needed!

<script type="module">
  import truffleDbLoader from 'https://cdn.skypack.dev/@truffle/db-loader';
</script>

README

@truffle/db-loader

A loader for importing Truffle Db that does not throw an error when it is not installed.

Contents

This package's main export is a method called getTruffleDb. To import it, simply destructure it from the package.

const { getTruffleDb } = require("@truffle/db-loader");

When you call the method, it will return an instance of Truffle Db or null if the import fails.

const Db = getTruffleDb();
if (Db === null) {
  throw new Error("There was an error importing Truffle Db.");
}

Note that you will need to do a check for a null value if you want to provide handling for the case where Truffle Db fails to load.

Please see the README for @truffle/db for more information on using Truffle Db.