lib/traildb.js
function (options) {
  if (!options.path) {
    throw new TrailDBError('Path is required');
  }
  if (!options.fieldNames || !options.fieldNames.length) {
    throw new TrailDBError('Field names are required');
  }

  if (options.path.slice(-4) === '.tdb') {
    options.path = options.path.slice(0, -4);
  }

  this._cons = lib.tdb_cons_init();
  this.numFields = options.fieldNames.length;

  const fieldNamesLength = ref.alloc(ref.types.uint64, this.numFields);
  const fieldNamesArray = new T_STRING_ARRAY(this.numFields);
  options.fieldNames.forEach(function (field, i) {
    fieldNamesArray[i] = ref.allocCString(field);
  });

  const r = lib.tdb_cons_open(
    this._cons,
    ref.allocCString(options.path),
    fieldNamesArray,
    ref.deref(fieldNamesLength)
  );
  if (r !== 0) {
    throw new TrailDBError('Cannot open constructor: ' + r);
  }

  this.path = options.path;
  this.fieldNames = options.fieldNames;

  return this;
}
function (options) {
  if (!options.path) {
    throw new TrailDBError('Path is required');
  }
  if (!options.fieldNames || !options.fieldNames.length) {
    throw new TrailDBError('Field names are required');
  }

  if (options.path.slice(-4) === '.tdb') {
    options.path = options.path.slice(0, -4);
  }

  this._cons = lib.tdb_cons_init();
  this.numFields = options.fieldNames.length;

  const fieldNamesLength = ref.alloc(ref.types.uint64, this.numFields);
  const fieldNamesArray = new T_STRING_ARRAY(this.numFields);
  options.fieldNames.forEach(function (field, i) {
    fieldNamesArray[i] = ref.allocCString(field);
  });

  const r = lib.tdb_cons_open(
    this._cons,
    ref.allocCString(options.path),
    fieldNamesArray,
    ref.deref(fieldNamesLength)
  );
  if (r !== 0) {
    throw new TrailDBError('Cannot open constructor: ' + r);
  }

  this.path = options.path;
  this.fieldNames = options.fieldNames;

  return this;
}
function ( options ) { if ( ! options . path ) { throw new TrailDBError ( 'Path is required' ) ; } if ( ! options . fieldNames || ! options . fieldNames . length ) { throw new TrailDBError ( 'Field names are required' ) ; } if ( options . path . slice ( - 4 ) === '.tdb' ) { options . path = options . path . slice ( 0 , - 4 ) ; } this . _cons = lib . tdb_cons_init ( ) ; this . numFields = options . fieldNames . length ; const fieldNamesLength = ref . alloc ( ref . types . uint64 , this . numFields ) ; const fieldNamesArray = new T_STRING_ARRAY ( this . numFields ) ; options . fieldNames . forEach ( function ( field , i ) { fieldNamesArray [ i ] = ref . allocCString ( field ) ; } ) ; const r = lib . tdb_cons_open ( this . _cons , ref . allocCString ( options . path ) , fieldNamesArray , ref . deref ( fieldNamesLength ) ) ; if ( r !== 0 ) { throw new TrailDBError ( 'Cannot open constructor: ' + r ) ; } this . path = options . path ; this . fieldNames = options . fieldNames ; return this ; }
TrailDBConstructor class Construct a new TrailDB.  
Initialize a new TrailDBConstructor.
@param {String} options.path - TrailDB output path (without .tdb).
@param {Array[String]} options.fieldNames - Array of field names in this TrailDB.
@return {Object} cons - TrailDB constructor object.
TrailDBConstructor class Construct a new TrailDB . Initialize a new TrailDBConstructor .