Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Sqlite UPDATE and INSERT logic to use ON CONFLICT #5081

Closed
franciscojavierarceo opened this issue Feb 21, 2025 · 0 comments
Closed

Update Sqlite UPDATE and INSERT logic to use ON CONFLICT #5081

franciscojavierarceo opened this issue Feb 21, 2025 · 0 comments
Labels
good first issue Good for newcomers kind/feature New feature or request starter-ticket Good starter tickets

Comments

@franciscojavierarceo
Copy link
Member

Is your feature request related to a problem? Please describe.
Migrate from this redundant code:

conn.execute(
    f"""
        UPDATE {table_name}
        SET value = ?, event_ts = ?, created_ts = ?
        WHERE (entity_key = ? AND feature_name = ?)
    """,
    (
        # SET
        val.SerializeToString(),
        timestamp,
        created_ts,
        # WHERE
        entity_key_bin,
        feature_name,
    ),
)

conn.execute(
    f"""INSERT OR IGNORE INTO {table_name}
        (entity_key, feature_name, value, event_ts, created_ts)
        VALUES (?, ?, ?, ?, ?)""",
    (
        entity_key_bin,
        feature_name,
        val.SerializeToString(),
        timestamp,
        created_ts,
    ),
)

To

conn.execute(
    f"""
    INSERT INTO {table_name} (entity_key, feature_name, value, event_ts, created_ts)
    VALUES (?, ?, ?, ?, ?)
    ON CONFLICT(entity_key, feature_name) DO UPDATE SET
        value = excluded.value,
        event_ts = excluded.event_ts,
        created_ts = excluded.created_ts;
    """,
    (
        entity_key_bin,          # entity_key
        feature_name,            # feature_name
        val.SerializeToString(), # value
        timestamp,               # event_ts
        created_ts               # created_ts
    ),
)

Describe the solution you'd like
Update with this code

Describe alternatives you've considered
N/A

Additional context
Should do this for sqlite-vec use cases too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/feature New feature or request starter-ticket Good starter tickets
Projects
None yet
Development

No branches or pull requests

1 participant