diff --git a/bin/manager.bat b/bin/manager.bat index 1cc849a..6e209a1 100644 --- a/bin/manager.bat +++ b/bin/manager.bat @@ -34,6 +34,15 @@ if /I "%1"=="--port" ( echo Using custom secret key: ***** shift shift +) else if /I "%1"=="--sqlite" ( + if "%2"=="" ( + echo Sqlite db path is not specified + exit + ) + set CRONICLE_sqlite=%~f2 + echo Using sqlite as storage: %~f2 + shift + shift ) else if /I "%1"=="--help" ( echo Usage: .\manager [--port port] [ --storage /path/to/storage.json] shift diff --git a/bin/storage-cli.js b/bin/storage-cli.js index 864feaf..6e7ed85 100755 --- a/bin/storage-cli.js +++ b/bin/storage-cli.js @@ -27,6 +27,24 @@ if(fs.existsSync(storage_config)) { config.Storage = require(storage_config) } +// overwrite storage if sqlite option is specified +if(process.env['CRONICLE_sqlite']) { + config.Storage = { + "engine": "SQL", + "list_page_size": 50, + "concurrency": 4, + "log_event_types": { "get": 1, "put": 1, "head": 1, "delete": 1, "expire_set": 1 }, + "SQL": { + "client": "sqlite3", + "table": "cronicle", + "useNullAsDefault": true, + "connection": { + "filename": process.env['CRONICLE_sqlite'] + } + } + } +} + // shift commands off beginning of arg array var argv = JSON.parse(JSON.stringify(process.argv.slice(2))); var commands = []; diff --git a/bundle.ps1 b/bundle.ps1 index f090982..df78f5d 100644 --- a/bundle.ps1 +++ b/bundle.ps1 @@ -54,7 +54,7 @@ foreach ($arg in $PSBoundParameters.Values) { } if($Path -like "--*") { - # perhaps user meant some flag, fallback Path to default + # User likely meant some flag, fallback Path to default $Path = "dist" } @@ -81,7 +81,7 @@ function Write-Bold { param($Text, [switch]$U) $FullPath = mkdir -Force $Path -Write-Bold "`nInstalling cronicle bundle into $FullPath`n" -U | Write-Host -ForegroundColor Green +Write-Bold "`nInstalling cronicle bundle into $FullPath`n" -U # Write-Host "-----------------------------------------" # Write-Host " Installing cronicle bundle into $($Path)" @@ -370,6 +370,7 @@ if($sqlDrivers.Count -gt 0) { $sqlArgs.Add("engines/SQL.js") | Out-Null Write-Host " - bundling SQL Engine [$($sqlDrivers -join ",")]" + $engines += ", SQL [$($sqlDrivers -join ",")]" & npm $sqlInstall & esbuild $sqlArgs if($Sqlite) { @@ -453,7 +454,7 @@ Write-Host " - Init cronicle storage (on the first run): node .\$Path\bin\stora Write-Host " - Start cronicle as manage: node .\$Path\bin\cronicle.js --echo --foreground --manager --color`n" Write-Bold "You can also setup/start cronicle using [manager] entrypoint:" -Write-Host ".\$Path\bin\manager [ --port 3012 ] [ --storage Path\to\storage.json ] [ --key someSecretKey ]`n" +Write-Host ".\$Path\bin\manager [ --port 3012 ] [ --storage Path\to\storage.json ] [ --sqlite Path\to\sqlite.db ] [ --key someSecretKey ]`n" Write-Bold "To Reinstall/upgrade run (please back up $FullPath first):" Write-Host ".\bundle.ps1 $Path -Force`n" diff --git a/lib/main.js b/lib/main.js index 6ce3b60..a8b3f9a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,10 +29,20 @@ if(fs.existsSync(config_file)) configFiles.push( { file: config_file }) -let storage_config = process.env['CRONICLE_storage_config'] || "conf/storage.json" -if(fs.existsSync(storage_config)) configFiles.push( { - file: storage_config , key: "Storage" -}) +// override storage config if needed +if (process.env['CRONICLE_sqlite']) { // use sqlite + process.env["CRONICLE_Storage__engine"] = "SQL" + process.env["CRONICLE_Storage__SQL__connection__filename"] = process.env['CRONICLE_sqlite'] + process.env["CRONICLE_Storage__SQL__client"] = "sqlite3" + process.env["CRONICLE_Storage__SQL__table"] = "cronicle" + process.env["CRONICLE_Storage__SQL__useNullAsDefault"] = 1 +} +else { // or resolve storage config from files + let storage_config = process.env['CRONICLE_storage_config'] || "conf/storage.json" + if (fs.existsSync(storage_config)) configFiles.push({ + file: storage_config, key: "Storage" + }) +} const server = new PixlServer({