Skip to content

Commit

Permalink
Add an api for giving local-dynamo more heap
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Santos committed Jun 22, 2015
1 parent 12733a8 commit 61beeba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
40 changes: 33 additions & 7 deletions lib/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,33 @@ var cp = require('child_process')
var path = require('path')

/**
* @param {?string} databaseDir The location of database files. Will run in memory if null.
* @param {number} port
* An options object:
* port: {number} - The port to run on. Required.
* dir: {?string=} - The location of database files. Optional Will run in-memory if null.
* heap: {?string=} - The amount of heap space, e.g., 512m. If not specified, uses JVM defaults.
* @typedef {Object}
*/
var Options;

/**
* @param {?string|Options} options The options object. For backwards compatibility,
* accepts a string as the database dir.
* @param {=number} port The port. Prefer using the options object.
* @return {ChildProcess}
*/
function launch(databaseDir, port) {
function launch(options, port) {
if (typeof options == 'string') {
options = {dir: options}
} else {
options = options || {}
}

options.port = options.port || port

if (isNaN(options.port)) {
throw Error('Port required')
}

var opts = {env: process.env}
var javaDir = path.join(__dirname, '..', 'aws_dynamodb_local')
var libDir = path.join(javaDir, 'DynamoDBLocal_lib')
Expand All @@ -23,13 +45,17 @@ function launch(databaseDir, port) {
'-jar',
path.join(javaDir, 'DynamoDBLocal.jar'),
'--port',
port
options.port
]

if (databaseDir === null) {
args.push('--inMemory')
if (options.heap) {
args.push('-Xmx=' + options.heap)
}

if (options.dir) {
opts.cwd = path.resolve(options.dir)
} else {
opts.cwd = path.resolve(databaseDir)
args.push('--inMemory')
}

return cp.spawn(cmd, args, opts)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "local-dynamo",
"description": "A Node.js wrapper of AWS DynamoDB Local and utilities",
"version": "0.0.6",
"version": "0.1.0",
"homepage": "https://github.com/Medium/local-dynamo",
"licenses": [
{
Expand Down

0 comments on commit 61beeba

Please sign in to comment.