<commit_before>const Realm = require('realm');

const schema = {
  schema: [
    { name: 'Alert',
      properties: {
        slug: 'string',
        long: 'float',
        lat: 'float'
      }
    }
  ]
};

export function initDb() {
  return new Realm(schema);
}

export function read(realm, object, eager = false) {
  return eager ? Array.from(realm.objects(object)) : realm.objects(object);
}

export function write(realm, object, data) {
  realm.write(() => {
    realm.create(object, data);
  });
}<commit_msg>Change sb schema and add comments<commit_after>// To dump Realm db => Realm.clearTestState()

const Realm = require('realm');

const schema = {
  schema: [
    { name: 'Alert',
      properties: {
        areaId: { type: 'string', indexed: true },
        slug: { type: 'string', indexed: true },
        long: 'float',
        lat: 'float'
      }
    }
  ]
};

export function initDb() {
  return new Realm(schema);
}

// realm objects are lazy loaded by default. Not easy to debug
export function read(realm, object, eager = false) {
  return eager ? Array.from(realm.objects(object)) : realm.objects(object);
}

export function write(realm, object, data) {
  realm.write(() => {
    realm.create(object, data);
  });
}
{'fraction_non_alphanumeric': 0.15347334410339256, 'fraction_numerical': 0.0, 'mean_word_length': 2.996774193548387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2322990', 'n_tokens_mistral': 402, 'n_tokens_neox': 402, 'n_words': 108}