Configuring SQLite API
SqliteModule requires at least one argument, but optionally takes two:
- fileName
The
String fileNameargument tells the SQLite API what the SQLite DB should be named when it's written to disk. The SQLite API automatically creates this in your plugin's data folder, and should include the.dbfile extension.- config
The
SqliteConfig configargument tells Java's SQLite Driver how to configure and use the DB. It also includes configuration for the built-inSqliteCache, which we'll read more about later.
Basic usage
SqliteConfig options
foreignKeys(boolean)Controls
PRAGMA foreign_keys=ON.Values:
true,false.Default:
true.
journalMode(String)Passed directly to
PRAGMA journal_mode=<value>.The library does not validate this value.
Common SQLite values:
WAL,DELETE,TRUNCATE,PERSIST,MEMORY,OFF.Default:
"WAL".
synchronous(String)Passed directly to
PRAGMA synchronous=<value>.The library does not validate this value.
Common SQLite values:
OFF,NORMAL,FULL,EXTRA(or numeric0-3).Default:
"NORMAL".
busyTimeoutMs(int)Passed to
PRAGMA busy_timeout=<value>.Unit: milliseconds.
Default:
5000.
mainThreadTimeout(Duration)Timeout applied to blocking DB calls made on the Bukkit main thread.
null, zero, or negative disables timeout behavior for main-thread calls.Default:
Duration.ofMillis(20).
mainThreadPolicy(MainThreadPolicy)Controls what happens when DB calls are made on the main thread.
Values:
ALLOW: permit silentlyWARN: permit and allow slow-call warningsDISALLOW: throwDbMainThreadDisallowedException
Default:
WARN.
timeoutBehavior(TimeoutBehavior)Controls behavior when a main-thread call exceeds
mainThreadTimeout.Values:
FAIL_OPEN: return fallback result (null; query wrappers convert to empty list)FAIL_CLOSED: throwDbTimeoutExceptionTHROW: throwDbTimeoutException
Default:
THROW.
slowQueryWarnThreshold(Duration)Used only when
mainThreadPolicy == WARN.If the elapsed main-thread DB call time is greater than or equal to this threshold, a warning is logged.
null, zero, or negative disables slow-query warning logs.Default:
Duration.ofMillis(10).
cache(SqliteConfig.CacheConfig)Query result cache settings.
Default:
SqliteConfig.CacheConfig.defaults().
CacheConfig options
ttl(Duration)Time-to-live for cache entries.
null, zero, or negative means entries do not expire by TTL.Default:
Duration.ofSeconds(30).
refreshAfter(Duration)Age after which reads may trigger background refresh.
null, zero, or negative disables refresh-after behavior.Default:
Duration.ofSeconds(10).
serveStaleWhileRefreshing(boolean)If
true, stale entries can be served while a refresh is running.Values:
true,false.Default:
true.
maxSize(int)Maximum number of cached query keys.
Special values:
0: disable cache-1: unlimited cache size< -1: disable cache
Default:
50000.