Skip to content

Commit

Permalink
added --sqlite option for manager (win) /storage-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeTWC1984 committed Apr 5, 2024
1 parent 0bc734c commit 0df1ce2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
9 changes: 9 additions & 0 deletions bin/manager.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions bin/storage-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
7 changes: 4 additions & 3 deletions bundle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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)"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 14 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({

Expand Down

0 comments on commit 0df1ce2

Please sign in to comment.