Ltijs Sequelize Database Plugin

2.4.4 · active · verified Wed Apr 22

Ltijs Sequelize Database Plugin is an official plugin for the LTI Advantage Complete Certified `ltijs` library, enabling it to persist LTI platform and deployment data using databases supported by Sequelize. It provides a robust, production-ready solution for managing LTI data with relational databases like MySQL, PostgreSQL, and MariaDB. The current stable version is 2.4.4, with releases often coinciding with new feature additions or compatibility updates for the core `ltijs` library, as seen with versions 2.4.0 and 2.3.0 introducing support for new `ltijs` features. This tight integration ensures seamless operation and access to advanced LTI features like Dynamic Registration Service and `authorizationServer` platform fields. Its primary differentiation is its certified compatibility and direct integration with `ltijs`, offering a tested and reliable database solution for LTI service providers.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize the `ltijs-sequelize` database plugin with specific Sequelize options (e.g., dialect, host) and integrate it with the `ltijs.Provider` instance, followed by deploying both the database schema and the LTI provider.

const path = require('path')

// Require Provider 
const lti = require('ltijs').Provider
const Database = require('ltijs-sequelize')

// Setup ltijs-sequelize using the same arguments as Sequelize's generic contructor
const db = new Database('database', 'user', 'password', 
  { 
    host: 'localhost',
    dialect: 'mysql', // Or 'postgres', 'mariadb', 'mssql', 'sqlite'
    logging: false,
    // Other Sequelize options like pool, define, etc.
    // Example: dialectOptions for SSL for PostgreSQL on Heroku
    // dialectOptions: {
    //   ssl: {
    //     require: true,
    //     rejectUnauthorized: false
    //   }
    // }
  })

// Setup provider, passing the db object to the plugin field
lti.setup(process.env.LTIJS_KEY ?? 'LTIKEY_YOUR_SECRET', // Key used to sign cookies and tokens. USE A STRONG RANDOM KEY!
  { 
    plugin: db // Passing db object to plugin field
  },
  { // Optional Ltijs configuration options
    appRoute: '/', 
    loginRoute: '/login', 
    cookies: {
      secure: process.env.NODE_ENV === 'production', // Set to true in production
      sameSite: 'none' // Required for cross-site LTI launches
    },
    // Other Ltijs options like devMode, staticPath, etc.
    // example: staticPath: path.join(__dirname, './public')
  })

// Example of how to initialize and connect
async function startLti() {
  try {
    await db.deploy(); // Deploys database schema, creates tables if they don't exist
    await lti.deploy(); // Deploys Ltijs, setting up routes and middleware
    console.log('LTI and Database plugin deployed successfully.');
  } catch (err) {
    console.error('Failed to deploy LTI or database plugin:', err);
    process.exit(1);
  }
}

startLti();

view raw JSON →