Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src_js/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ class Database {
* @param {Number} checkpointThreshold threshold for automatic checkpointing
* in bytes. Default is 16MB.
*/
// Settings default to null (= engine default); they are forwarded as-is to
// the sync implementation, which only applies non-null values.
constructor(
databasePath,
bufferPoolSize = 0,
maxNumThreads = 0,
enableCompression = true,
readOnly = false,
autoCheckpoint = true,
checkpointThreshold = 16777216
bufferPoolSize = null,
maxNumThreads = null,
enableCompression = null,
readOnly = null,
autoCheckpoint = null,
checkpointThreshold = null
) {
this._isInitialized = false;
this._initPromise = null;
Expand Down
13 changes: 7 additions & 6 deletions src_js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ export declare class PreparedStatement {
*/
export declare class Database {
/**
* Any setting left undefined uses the engine default; explicitly set settings override it.
* @param databasePath Path on disk, or `:memory:` / `""` for in-memory. Defaults to `:memory:`.
* @param bufferPoolSize Buffer pool size in bytes. 0 = use default.
* @param maxNumThreads Maximum threads for parallel query execution. 0 = use all available.
* @param enableCompression Whether to compress column data on disk. Default true.
* @param readOnly Open the database in read-only mode. Default false.
* @param autoCheckpoint Enable automatic WAL checkpointing. Default true.
* @param checkpointThreshold WAL size threshold (bytes) that triggers a checkpoint. Default 16 MB.
* @param bufferPoolSize Buffer pool size in bytes (engine default if omitted).
* @param maxNumThreads Maximum threads for parallel query execution (engine default if omitted).
* @param enableCompression Whether to compress column data on disk (engine default if omitted).
* @param readOnly Open the database in read-only mode (engine default if omitted).
* @param autoCheckpoint Enable automatic WAL checkpointing (engine default if omitted).
* @param checkpointThreshold WAL size threshold (bytes) that triggers a checkpoint (engine default if omitted).
*/
constructor(
databasePath?: string,
Expand Down
76 changes: 45 additions & 31 deletions src_js/sync/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@ class Database {
/**
* Initialize a new Database object.
*
* @param {String} databasePath path to the database file. If the path is not
* specified, or empty, or equal to`:memory:`, the database will be created in
* Any setting left as null/undefined is not forwarded, so the engine default
* applies and engine-side default changes propagate automatically.
*
* @param {String} databasePath path to the database file. If the path is not
* specified, or empty, or equal to`:memory:`, the database will be created in
* memory.
* @param {Number} bufferManagerSize size of the buffer manager in bytes.
* @param {Boolean} enableCompression whether to enable compression.
* @param {Boolean} readOnly if true, database will be opened in read-only
* mode.
* @param {Boolean} autoCheckpoint if true, automatic checkpointing will be
* enabled.
* @param {Number} checkpointThreshold threshold for automatic checkpointing
* in bytes. Default is 16MB.
* @param {Number|null} bufferPoolSize size of the buffer manager in bytes. Null (default) uses the engine default.
* @param {Number|null} maxNumThreads maximum number of threads available. Null (default) uses the engine default.
* @param {Boolean|null} enableCompression whether to enable compression. Null (default) uses the engine default.
* @param {Boolean|null} readOnly if true, database will be opened in read-only
* mode. Null (default) uses the engine default.
* @param {Boolean|null} autoCheckpoint if true, automatic checkpointing will be
* enabled. Null (default) uses the engine default.
* @param {Number|null} checkpointThreshold threshold for automatic checkpointing
* in bytes. Null (default) uses the engine default.
*/
constructor(
databasePath,
bufferPoolSize = 0,
maxNumThreads = 0,
enableCompression = true,
readOnly = false,
autoCheckpoint = true,
checkpointThreshold = 16777216
bufferPoolSize = null,
maxNumThreads = null,
enableCompression = null,
readOnly = null,
autoCheckpoint = null,
checkpointThreshold = null
) {
LbugWasm.checkInit();
const lbug = LbugWasm._lbug;
Expand All @@ -39,27 +43,37 @@ class Database {
else if (typeof databasePath !== "string") {
throw new Error("Database path must be a string.");
}
if (typeof bufferPoolSize !== "number" || bufferPoolSize < 0) {
if (bufferPoolSize != null && (typeof bufferPoolSize !== "number" || bufferPoolSize < 0)) {
throw new Error("Buffer manager size must be a positive integer.");
}
if (typeof maxNumThreads !== "number" || maxNumThreads < 0) {
if (maxNumThreads != null && (typeof maxNumThreads !== "number" || maxNumThreads < 0)) {
throw new Error("Max number of threads must be a positive integer.");
}
if (typeof checkpointThreshold !== "number" || checkpointThreshold < 0) {
// Note: negative explicit values are accepted here and ignored below,
// which keeps the engine default for them.
if (checkpointThreshold != null && typeof checkpointThreshold !== "number") {
throw new Error("Checkpoint threshold must be a positive integer.");
}
bufferPoolSize = Math.floor(bufferPoolSize);
const defaultSystemConfig = new lbug.SystemConfig();
const systemConfig = new lbug.SystemConfig(
bufferPoolSize,
maxNumThreads,
!!enableCompression,
!!readOnly,
defaultSystemConfig.maxDBSize,
!!autoCheckpoint,
checkpointThreshold
);
defaultSystemConfig.delete();
// Start from the engine defaults; only apply explicitly set settings.
const systemConfig = new lbug.SystemConfig();
if (bufferPoolSize != null) {
systemConfig.bufferPoolSize = Math.floor(bufferPoolSize);
}
if (maxNumThreads != null) {
systemConfig.maxNumThreads = Math.floor(maxNumThreads);
}
if (enableCompression != null) {
systemConfig.enableCompression = !!enableCompression;
}
if (readOnly != null) {
systemConfig.readOnly = !!readOnly;
}
if (autoCheckpoint != null) {
systemConfig.autoCheckpoint = !!autoCheckpoint;
}
if (checkpointThreshold != null) {
systemConfig.checkpointThreshold = Math.floor(checkpointThreshold);
}
try {
this._database = new lbug.Database(databasePath, systemConfig);
} finally {
Expand Down
13 changes: 7 additions & 6 deletions src_js/sync/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ export declare class PreparedStatement {
*/
export declare class Database {
/**
* Any setting left undefined uses the engine default; explicitly set settings override it.
* @param databasePath Path on disk, or `:memory:` / `""` for in-memory. Defaults to `:memory:`.
* @param bufferPoolSize Buffer pool size in bytes. 0 = use default.
* @param maxNumThreads Maximum threads for parallel query execution. 0 = use all available.
* @param enableCompression Whether to compress column data on disk. Default true.
* @param readOnly Open the database in read-only mode. Default false.
* @param autoCheckpoint Enable automatic WAL checkpointing. Default true.
* @param checkpointThreshold WAL size threshold (bytes) that triggers a checkpoint. Default 16 MB.
* @param bufferPoolSize Buffer pool size in bytes (engine default if omitted).
* @param maxNumThreads Maximum threads for parallel query execution (engine default if omitted).
* @param enableCompression Whether to compress column data on disk (engine default if omitted).
* @param readOnly Open the database in read-only mode (engine default if omitted).
* @param autoCheckpoint Enable automatic WAL checkpointing (engine default if omitted).
* @param checkpointThreshold WAL size threshold (bytes) that triggers a checkpoint (engine default if omitted).
*/
constructor(
databasePath?: string,
Expand Down
Loading