question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying and saving rows directly

See original GitHub issue

Hi!

I have a use-case where I have to modify multiple properties of a row in different parts of the code, so I had to make a lot of UPDATE statements, which is a lot of boilerplate and I’m not sure if it’s the right approach.

Instead, I was thinking if it would be possible to make the properties of the generated interface mutable, and then update the table with the row as an input. Something similar like this feature #757 but instead of an insert, it could be an update with the row as an input and with a dynamic where.

Does it make any sense as a feature request or is there a better way to update multiple properties already?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ashughescommented, Feb 23, 2019

Actually, I figured it out by looking at #505. For anyone else wondering, here’s an example:

-- User.sq

CREATE TABLE user(
  id TEXT NOT NULL
  name TEXT NOT NULL,
  created INTEGER NOT NULL
);

insertOrReplace:
INSERT OR REPLACE INTO user VALUES ?;

insertOrReplaceJustName:
INSERT OR REPLACE INTO user(name) VALUES ?;

get:
SELECT * FROM user WHERE id = ?;
fun updateUserName(userId: String, name: String) {
    val user = db.userQueries.get(userId).executeAsOne() as User.Impl
    val updatedUser = user.copy(name = name)
    db.userQueries.insertOrReplace(updatedUser)
}

@AlecStrong Is this what you meant? Please let me know if there’s anything I’m misunderstanding or could do better.

0reactions
AlecStrongcommented, Feb 23, 2019

nope you got it 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add, edit, find, and delete rows by using a data form
In a data form, you can enter new rows, find rows by navigating, or (based on cell contents) update rows and delete rows....
Read more >
Change and save only one row in a file - Stack Overflow
I know, that I can read file, change Species, and save it again, but the more rows (i.e. > 10 6 ) I...
Read more >
Tutorial: Adding and Saving Rows: Databases for Developers
Tutorial Adding and Saving Rows: Databases for Developers; Description An introduction to adding rows to tables with insert.
Read more >
Edit and Delete Rows - Anvil Works
This is great, but what if I accidentally add the wrong data? Usually you'll want to allow editing the data and deleting rows...
Read more >
1.2 Entering, Editing, and Managing Data – Beginning Excel ...
Adjusting Columns and Rows · Click any cell location in Column A by moving the mouse pointer over a cell location and clicking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found