Skip to content

Instantly share code, notes, and snippets.

let doc = { type: 'string' };
console.log(BSON.serialize(doc));
// <Buffer 16 00 00 00 02 74 79 70 65 00 07 00 00 00 73 74 72 69 6e 67 00 00>
let doc = { _id: 1 };
console.log(BSON.serialize(doc));
// <Buffer 0e 00 00 00 10 5f 69 64 00 01 00 00 00 00>
const doc = {};
console.log(BSON.serialize(doc));
// <Buffer 05 00 00 00 00>
interface Column {
_id: string; // MongoDB id field
type: 'string'; // yes, it is literally 'string'
values: (string | null)[]; // an array, each element is either string or null
}
async function findOneMongoDB(query) {
/* implemented somewhere */
}
async function get(query) {
let doc = await findOneMongoDB(query);
// return doc at once if it is not splitted
if (!doc._splitted) return doc;
const { _id, type } = doc;
// use unique uuids
const { v4: uuidv4 } = require('uuid');
// split will be done if values size exceed ~15Mb
const SPLIT_SIZE = 15e6;
async function insertOneMongoDB(_id, data) {
/* implemented somewhere */
}
function compress(column) {
column.compression = 'DICTIONARY';
const dictionary = [];
const indexes = {};
column.values = column.values.map(value => {
if (value === null) return null;
// add string to dictionary if there is no such string yet
if (indexes[value] === undefined) {
indexes[value] = dictionary.length;
function compress(column) {
column.compression = 'ZIP_JSON_STRINGIFY';
column.values = zip(JSON.stringify(column.values));
return column;
}
interface ColumnOfStrings {
_id: string; // MongoDB id field
type: 'string'; // yes, it is literal 'string' for column of strings
values: (string | null)[]; // an array, each element is either string or null
}
const recursiveFn = trampoline(function _recursiveFn(n) {
if (n < 0) return;
return () => _recursiveFn(n - 1);
});
recursiveFn(100000);
console.log('No range error!');