<commit_before>//----------------------------------------------------------------------------------------------------------------------
// A playful example, using characters from "Dr. Horrible's Sing Along Blog".
//
// @module horrible_example.js
//----------------------------------------------------------------------------------------------------------------------

var util = require('util');
var trivialdb = require('../trivialdb');

//----------------------------------------------------------------------------------------------------------------------

function pprint(obj)
{
    return util.inspect(obj, {colors: true, depth: null});
} // end pprint

//----------------------------------------------------------------------------------------------------------------------

// Create a new example db
var db = trivialdb.db('example', { writeToDisk: false });

// Create some new keys
var hammerID, horribleID, moistID, pennyID;
db.store({ name: "<NAME>", role: 'hero', nemeses: [] })
    .then(function(id)
    {
        hammerID = id;
        return db.store({name: "<NAME>", role: 'villain', nemeses: []});
    })
    .then(function(id)
    {
        horribleID = id;
        return db.store({ name: "Moist", role: 'henchman', nemeses: [] });
    })
    .then(function(id)
    {
        moistID = id;
        return db.store({ name: "Penny", role: 'love interest', nemeses: []});
    })
    .then(function(id)
    {
        pennyID = id;

        // We've finished adding values, so print out the database:
        console.log('\n[Step 1] db.values:\n%s', pprint(db.values));
    })
    .then(function()
    {
        // Update some values
        return db.merge(hammerID, { nemeses: [horribleID], loveInterest: pennyID });
    })
    .then(function()
    {
        // Update some values
        return db.merge(horribleID, { nemeses: [hammerID], loveInterest: pennyID });
    })
    .then(function()
    {
        // We've finished updating values, so print out the database:
        console.log('\n[Step 2] db.values:\n%s', pprint(db.values));
    })
    .then(function()
    {
        // Find everyone for whom Penny is a love interest
        return db.filter(function(key, value)
        {
            return value.loveInterest == pennyID;
        });
    })
    .then(function(lovesPenny)
    {
        // Finally, print out everyone who loves Penny
        console.log('\n[Step 3] people who love Penny:\n%s', pprint(lovesPenny));
    });

//----------------------------------------------------------------------------------------------------------------------<commit_msg>converted horrible example.<commit_after>//----------------------------------------------------------------------------------------------------------------------
// A playful example, using characters from "Dr. Horrible's Sing Along Blog".
//
// @module horrible_example.js
//----------------------------------------------------------------------------------------------------------------------

var Promise = require('bluebird');
var util = require('util');
var trivialdb = require('../trivialdb');

//----------------------------------------------------------------------------------------------------------------------

function pprint(obj)
{
    return util.inspect(obj, {colors: true, depth: null});
} // end pprint

//----------------------------------------------------------------------------------------------------------------------

// Create a new example db
var db = trivialdb.db('example', { writeToDisk: false });

// Create some new keys
var hammerID, horribleID, moistID, pennyID;
Promise.resolve()
    .then(() =>
    {
        return Promise.join(
            db.save({ name: "<NAME>", role: 'hero', nemeses: [] }).then((id) => { hammerID = id; }),
            db.save({name: "Dr. Horrible", role: 'villain', nemeses: []}).then((id) => { horribleID = id; }),
            db.save({ name: "Moist", role: 'henchman', nemeses: [] }).then((id) => { moistID = id; }),
            db.save({ name: "Penny", role: 'love interest', nemeses: []}).then((id) => { pennyID = id; })
        );
    })
    .then(() =>
    {
        // We've finished adding values, so print out the database:
        console.log('\n[Step 1] db.values:\n%s', pprint(db.values));
    })
    .then(() =>
    {
        // Update some values
        var hammer = db.get(hammerID);
        hammer.nemeses = [horribleID];
        hammer.loveInterest = pennyID;

        return db.save(hammer);
    })
    .then(() =>
    {
        // Update some values
        var horrible = db.get(horribleID);
        horrible.nemeses = [hammerID];
        horrible.loveInterest = pennyID;
        return db.save(horrible);
    })
    .then(() =>
    {
        // We've finished updating values, so print out the database:
        console.log('\n[Step 2] db.values:\n%s', pprint(db.values));
    })
    .then(() =>
    {
        // Find everyone for whom Penny is a love interest
        return db.filter({ loveInterest: pennyID });
    })
    .then((lovesPenny) =>
    {
        // Finally, print out everyone who loves Penny
        console.log('\n[Step 3] people who love Penny:\n%s', pprint(lovesPenny));
    });

//----------------------------------------------------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.3556856819040423, 'fraction_numerical': 0.0011333585190782018, 'mean_word_length': 1.196184155951887, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3923065', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1317, 'n_words': 344}