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
Unknown Object (File)
Mar 9 2024, 10:31 PM
Unknown Object (File)
Mar 7 2024, 1:54 PM
Unknown Object (File)
Mar 7 2024, 11:52 AM
Unknown Object (File)
Feb 19 2024, 2:10 PM
Unknown Object (File)
Feb 15 2024, 2:28 PM
Unknown Object (File)
Feb 13 2024, 2:40 AM
Unknown Object (File)
Feb 11 2024, 8:36 PM
Unknown Object (File)
Feb 9 2024, 12:20 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
Lint Not Applicable
Unit
Tests Not Applicable

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.