Skip to content

sqlx does not allow setting persistence of QueryAs, QueryScalar #1503

Closed

Description

@philippeitis

sqlx provides functionality for setting the persistence of Query, but not QueryAs, QueryScalar.

In my case, I'm using caching to store parsed data from SQLite, and I only load data which is not in the cache, using WHERE ... IN (uncached_ids). However, each of these statements is very likely to be unique, which causes sqlx to cache a lot of similar statements and bloat memory usage in my application.

Activity

  1. abonander commented on Oct 20, 2021

    @abonander
    Collaborator

    This should be a pretty easy fix, just copy the method from Query: https://github.com/launchbadge/sqlx/blob/master/sqlx-core/src/query.rs#L100

    QueryAs wraps Query and QueryScalar wraps QueryAs so the implementation for the new methods would just be self.inner.persistent(value);

    Ignore the persistent() method in the Execute impls, that's the getter for the set value and it's already implemented correctly for all three types; we should probably rename that to is_persistent() to be _con_sistent with Rust idioms but that can be done another time.

  2. added a commit that references this issue on Nov 3, 2021
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

    E-easygood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions