Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.
/ ordbok-knex Public archive

Orðbók Old Norse dictionary - SQL implementation with Knex.js

License

Notifications You must be signed in to change notification settings

stscoundrel/ordbok-knex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: