Page MenuHomePhabricator

Refactor all remove queries not to use ORM
ClosedPublic

Authored by marcin on Jan 18 2024, 9:13 AM.
Tags
None
Referenced Files
F3353097: D10707.diff
Sat, Nov 23, 8:12 AM
Unknown Object (File)
Wed, Nov 6, 5:17 PM
Unknown Object (File)
Oct 23 2024, 8:57 PM
Unknown Object (File)
Oct 15 2024, 12:39 PM
Unknown Object (File)
Oct 15 2024, 12:39 PM
Unknown Object (File)
Oct 15 2024, 12:38 PM
Unknown Object (File)
Sep 4 2024, 8:30 AM
Unknown Object (File)
Aug 27 2024, 11:57 AM
Subscribers

Details

Summary

This differential refactors all remove queries not to use ORM.

Test Plan

Execute tests in https://phab.comm.dev/D10711. Remove queries are covered there.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

marcin edited the test plan for this revision. (Show Details)
kamil requested changes to this revision.Jan 25 2024, 6:42 AM
kamil added inline comments.
native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
1114–1125 ↗(On Diff #35798)

you can call executeQuery and use something like this:

UPDATE OR REPLACE drafts
SET key = $newKey, text = (SELECT text FROM drafts WHERE key = $oldKey)
WHERE key = $oldKey
1117 ↗(On Diff #35798)

length() seems more natural

1220 ↗(On Diff #35798)

we can define it below, under if statement

native/cpp/CommonCpp/DatabaseManagers/entities/EntityQueryHelpers.h
139–147 ↗(On Diff #35798)

I think you can do something like this

145 ↗(On Diff #35798)

I think it's better to allow the caller to add ; - it could be confusing because array is not always the last part of SQL query

This revision now requires changes to proceed.Jan 25 2024, 6:42 AM
native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
1114–1125 ↗(On Diff #35798)

I am hesitant about this. It would be hard to write a template function that could handle a query like this for any table. Additionally from you comment: https://phab.comm.dev/D10707#inline-65624 I assume that you didn't want to write such query for message table since it would be unnecessarily complicated.

I think we don't have to force ourselves to write SQL query for everything just because we are removing ORM. I think it is fine to use a sequence of calls to SQLiteQueryExecutor methods.

If you disagree the request changes and I will replace this with single query.

1117 ↗(On Diff #35798)

The convention across our C++ code is to use size() when checking for an empty string.

native/cpp/CommonCpp/DatabaseManagers/entities/EntityQueryHelpers.h
139–147 ↗(On Diff #35798)

We can't - such constructor doesn't exist: https://en.cppreference.com/w/cpp/string/basic_string/basic_string
What you suggested is going to copy first length -1 characters of "?, " string. There are ways to do without looping: https://stackoverflow.com/questions/5689003/how-to-implode-a-vector-of-strings-into-a-string-the-elegant-way, but they either use external libraries or are complex and don't increase readability.

  1. Refactor getSQLStatementArray function not to end statement
  2. Move moveDraft and rekeyMessage refactor one diff up.
kamil added inline comments.
native/cpp/CommonCpp/DatabaseManagers/entities/EntityQueryHelpers.h
139–147 ↗(On Diff #35798)

ahh right

This revision is now accepted and ready to land.Feb 2 2024, 4:05 AM
This revision was automatically updated to reflect the committed changes.