Skip to content

feat: add native SQLite function mode and deprecate legacy overrides - #647

Open
lovasoa wants to merge 2 commits into
masterfrom
native-math-legacy-option
Open

lovasoa wants to merge 2 commits into
masterfrom
native-math-legacy-option

Conversation

@lovasoa

@lovasoa lovasoa commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

This gives applications a way to use SQLite's own math functions now, ahead of changing the default in the next major release. It also adds the missing native functions (ln, log2, mod, trunc, pow, ceiling, and two-argument log) in both modes.

Existing query results are preserved by default (useOldExtensionFunctions: true). Calling a legacy function now prints a deprecation warning naming it and linking to #619. Initialization and ordinary SQL stay quiet. Warnings are not suppressed: a scalar function applied to every row can produce many messages, including for functions such as sqrt whose ordinary numeric results look unchanged.

To try native behavior:

const SQL = await initSqlJs({ useOldExtensionFunctions: false });

Consequences of opting in:

  • log(x) becomes base 10. Use ln(x) to preserve natural-log calculations.
  • Invalid inputs can change results: sqrt('abc') and sign('abc') return NULL rather than zero, and sign(2.5) returns an integer rather than a real.
  • Legacy-only functions, including stdev, variance, mode, median, the quartiles, and string helpers such as reverse and charindex, are unavailable. Saved queries, views, or triggers using them will need changes too.
  • Native sign() can be used in expression indexes and generated columns, allowing schemas affected by Bundled extension-functions.c replaces SQLite's built-in sign() #646 to work. This remains opt-in; the default keeps the old override.

The first initialization chooses the mode for all databases from that module. For workers, set config: { useOldExtensionFunctions: false } on the first message. Native mode is silent; applications can use it to find migration problems before the default changes.

Related: #619, #646.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant