Skip to content

Add example of finding the html in relation to ember-cli-deploy and the sql plugin #1

@knownasilya

Description

@knownasilya
'use strict';

const db = require('./db');

exports.findByKey = async function findByKey(key, project) {
  let result;
  
  try {
    result = await db(`${project}_bootstrap`)
      .select()
      .where('key', key)
      .limit(1);
    
    if (!result || !result.length) {
      result = await exports.findActive(project);
    }
  } catch(e) {
    result = await exports.findActive(project);
  }

  return returnFirst(result);
};

exports.findActive = async function findActive(project) {
  let result = await db(`${project}_bootstrap`)
    .select()
    .where('is_active', true)
    .limit(1);

  if (!result || !result.length) {
    result = await db(`${project}_bootstrap`)
      .select()
      .orderBy('created_at')
      .limit(1);
  }

  return returnFirst(result);
};

function returnFirst(result) {
  return result && result.length ? result[0] : {};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions