镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

node:sqlite: DatabaseSync.function wrapper for sqlite3_create_function_v2 should allow use of xStep and xFinal parameters #56510

Closed

Description

@turbocrime

i want to create user-defined aggregate functions when using my sqlite database. sqlite expects aggregate functions to be defined with the same api as typical user-defined functions, plus additional aggregation parameters.

node:sqlite provides access to the sqlite function definition api with a wrapper for sqlite3_create_function_v2 as the instance method DatabaseSync.function

but, this wrapper always passes null for the aggregation parameter refs.

node/src/node_sqlite.cc

Lines 669 to 677 in 3b5f235

int r = sqlite3_create_function_v2(db->connection_,
*name,
argc,
text_rep,
user_data,
UserDefinedFunction::xFunc,
nullptr,
nullptr,
UserDefinedFunction::xDestroy);

implementation suggestions

  • a separate wrapper function, possibly called aggregate or reduce, for user-defined functions that use these additional callback parameters
  • optional parameters for function that accept the callbacks, in the same order as the sqlite api
  • additional attributes on the function options parameter object

Activity

  1. turbocrime commented on Jan 7, 2025

    @turbocrime
    Author

    i created this issue from the line highlight menu on node_sqlite.cc, so i didn't get the template prompt or label selection. sorry if this is out-of-order

  2. cjihrig commented on Jan 7, 2025

    @cjihrig
    Contributor

    a separate wrapper function, possibly called aggregate or reduce, for user-defined functions that use these additional callback parameters

    That is the plan - similar to how it is done in better-sqlite3.

  3. turbocrime commented on Jan 7, 2025

    @turbocrime
    Author

    is there a place for collected discussion and public work on this builtin?

  4. cjihrig commented on Jan 7, 2025

    @cjihrig
    Contributor

    Not that I am aware of.

  5. geeksilva97 commented on Jan 13, 2025

    @geeksilva97
    Contributor

    better-sqlite3 uses sqlite3_create_window_function though.

    I think implementing aggregate like this would end up solving #56511 as well.

  6. turbocrime commented on Jan 13, 2025

    @turbocrime
    Author

    better-sqlite3 uses sqlite3_create_window_function though.

    sqlite api treats window aggregate functions as distinct from other types of aggregate functions. a wrapper that combines the metaphors must use the api conditionally.

    your linked example also uses the v2 api on line 316

  7. geeksilva97 commented on Jan 13, 2025

    @geeksilva97
    Contributor

    better-sqlite3 uses sqlite3_create_window_function though.

    sqlite api treats window aggregate functions as distinct from other types of aggregate functions. a wrapper that combines the metaphors must use the api conditionally.

    your linked example also uses the v2 api on line 316

    I see.

    The linked example is for aggregate function specifically.

    From other issues, I can see that node:sqlite tries to be compatible with better-sqlite3. So, I think that, from this comment, using the sqlite3_create_window_function would be suitable.

  8. added
    sqliteIssues and PRs related to the SQLite subsystem.
    on Apr 7, 2025
  9. cjihrig commented on Apr 9, 2025

    @cjihrig
    Contributor

    Fixed by #56600

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    sqliteIssues and PRs related to the SQLite subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions