ordbok-knex

1.0.0 • Public • Published

Orðbók Knex

Old Norse dictionary for Node.js. SQL implementation with Knex.js.

Uses Orðbók for dictionary data.

Install

yarn add ordbok-knex

You also need to install the database driver you're going to use with Knex.

npm install pg
npm install sqlite3
npm install mysql
npm install mysql2

Usage

Orðbók-knex offers two methods: one for setting up new database, and one for getting Knex instance tied to them. Under the hood Orðbók is used to scrape the dictionary with Puppeteer.

Setting up the database
const { createDB } = require('ordbok-knex')

// Your Knew config. DO NOT define migrations folder.
const knexConf = {
  client: 'sqlite3',
  useNullAsDefault: true,
  connection: {
    filename: './local.db',
  },
  pool: {
    afterCreate: (conn, cb) => {
      conn.run('PRAGMA foreign_keys = ON', cb);
    },
  },
}

// Run only once to create & populate the database.
try {
    const res = await createDB(knexConf)
  } catch (err) {
    console.log(err)
  }
Queries
const { getKnex } = require('ordbok-knex')

/**
 * Setup Knex.
 * You can also do this step withour Orðbók.
 */
const knexConf = { // Your config }
const knex = await getKnex(knexConf)

// Any valid Knex query. 
const result = await knex('norse')
    .where({ startsWith: 'ó' })

const result2 = await knex('english')
    .where({ startsWith: 's' })

console.log(result)
console.log(result2)

knex.destroy()

Sources

Scraped from word list compiled by Vikings of Bjornstad. The sources for the compiled list come from:

Readme

Keywords

none

Package Sidebar

Install

npm i ordbok-knex

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.35 kB

Total Files

12

Last publish

Collaborators

  • stscoundrel