{"size": 2375, "ext": "js", "max_stars_repo_path": "tools/create_table.js", "max_stars_repo_name": "ashcharles/openset", "max_stars_repo_stars_event_min_datetime": "2017-09-28T16:46:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-13T19:32:04.000Z", "max_issues_repo_path": "tools/create_table.js", "max_issues_repo_name": "perple-io/openset", "max_issues_repo_issues_event_min_datetime": "2017-10-05T13:40:48.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-18T15:44:44.000Z", "max_forks_repo_path": "tools/create_table.js", "max_forks_repo_name": "perple-io/openset", "max_forks_repo_forks_event_min_datetime": "2017-12-07T22:34:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-17T00:19:43.000Z"}
{"max_stars_count": 18, "max_issues_count": 14, "max_forks_count": 4, "avg_line_length": 22.4056603774, "max_line_length": 81, "alphanum_fraction": 0.4597894737}
#!/usr/bin/node

/*
Openset - create_table.js
*/

fs = require('fs')
async = require('async')
openset = require('openset')

try {
    var args = require('command-line-args')([{
        name: 'help',
        type: String
    }, {
        name: 'host',
        alias: 'h',
        type: String,
        defaultValue: "127.0.0.1"
    }, {
        name: 'port',
        alias: 'p',
        type: Number,
        defaultValue: 2020
    }, {
        name: 'table',
        alias: 't',
        type: String,
    }, {
        name: 'json',
        alias: 'j',
        type: String,
    }])
} catch (ex) {
    var args = {
        help: true
    }
}

console.log('\n\n-----------------------------------------------------')
console.log(' OpenSet - create_table')
console.log('-----------------------------------------------------\n')
console.log(' -h --host <ip address>          // default 127.0.0.1')
console.log(' -p --port <port>                // default 2020')
console.log(' -t --table <name of table>      // no spaces, underscore allowed')
console.log(' -j --json <JSON table file>     //')
console.log('    --help                       // display help')
console.log('')

if (args.help || !args.table || !args.json) {
    console.log('')
    process.exit(0)
}

try {
    var data = require(args.json);
} catch (ex) {
    console.log('! could not open JSON table file.')
    console.log('')
    console.log('')
    process.exit(1)
}

if (!Array.isArray(data)) {
    console.log('! JSON data must be an array.')
    console.log('')
    console.log('')
    process.exit(1)
}

console.log('+ using ' + args.host + ':' + args.port + '\n');

// init the OpenSet SDK
conn = openset.init({
    host: args.host,
    port: args.port
});

command = {
    action: "create_table",
    params: {
        table: args.table,
        columns: data // should be array
    }
};

conn.rawRequest(
    openset.rpc.admin,
    command,
    (err, data) => {

        if (err) {
            console.log("! error")
            console.log('')
            console.log(err)
            console.log("\n\n")
            process.exit(1)
        }

        console.log(JSON.stringify(JSON.parse(data), null, 4))
        console.log('')
        console.log("+ done\n\n")
        process.exit(0)
    }
);
