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.

Support Grouping Multiple SQL Statements

See original GitHub issue

Background I would like bring up the conversation of supporting grouping multiple SQL statements together to make it possible to use a single model in Java/Kotlin.

Usage Following is a simple use case.

Let’s say we have two tables:

salary
+-----+-----------------+--------+
| _id | title           | salary |
+-----+-----------------+--------+
| 1   | Sales Associate | 1000   |
+-----+-----------------+--------+
| 2   | Manager         | 1500   |
+-----+-----------------+--------+

salaryChangeNotes
+-----+----------+------------------------------------------+
| _id | time     | updateNote                               |
+-----+----------+------------------------------------------+
| 1   | 20170918 | Increase manager's salary to 1500        |
+-----+----------+------------------------------------------+
| 2   | 20180417 | Increase sale associate's salary to 1000 |
+-----+----------+------------------------------------------+

Every time we update the salary table, we would like to insert a note into salaryChangeNotes table.

One possible implementation probably would be like this:

salary.sq

// ... create table, other logic, etc

GROUP_STATEMENTS updateSalaryRecord {

UPDATE salary
SET salary=?
WHERE title=?;

INSERT INTO salaryChangeNotes(time, updateNote)
VALUES(?, ?);

}

So in business logic, we only need to call

updateSalaryModel.bind(2000, "Manager", "20180418", "Increase manager's salary to 2000");
// Wrap return values from multiple sql statements is something we need to take care of
int updated = updateNumber.executeGroupStatement();

With more statements being grouped together, the implementation of this feature will be cleaner compared with the current approach.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
AlecStrongcommented, Jun 8, 2020

yes it is done, i just have to write the code

2reactions
eygrabercommented, Sep 3, 2019

Any update on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to SQL GROUP BY Multiple Columns - eduCBA
SQL GROUP BY multiple columns is the technique using which we can retrieve the summarized result set from the database using the SQL...
Read more >
What Is the SQL GROUPING SETS Clause, and How Do You ...
GROUPING SETS in SQL can be considered an extension of the GROUP BY clause. It allows you to define multiple grouping sets in...
Read more >
SQL GROUP BY Statement - W3Schools
The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group...
Read more >
Use a union query to combine multiple queries into a single ...
On the Create tab, in the Queries group, click Query Design. · On the Design tab, in the Query group, click Union. ·...
Read more >
Group by Multiple Columns in SQL - Scaler Topics
To arrange similar (identical) data into groups, we use SQL GROUP BY clause. The SQL GROUP BY clause is used along with some...
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