-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sample to class reserved select queries
By creating a class with a pre-written selection query and defining rows, you can build queries using IntelliSense.
- Loading branch information
Showing
4 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Carbunql.Postgres; | ||
namespace Carbunql.Postgres; | ||
|
||
public class SelectQuery<T> : SelectQuery | ||
{ | ||
public SelectQuery() : base() | ||
{ | ||
} | ||
|
||
public SelectQuery(string query) : base(query) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Carbunql.Postgres.Test; | ||
|
||
public static class SampleQuery | ||
{ | ||
public static string CommandText => | ||
""" | ||
SELECT | ||
a.a_id, | ||
a.text, | ||
b.value | ||
FROM | ||
table_a AS a | ||
INNER JOIN table_b AS b ON a.a_id = b.a_id | ||
"""; | ||
|
||
public static SelectQuery<Row> Query => GetQuery(); | ||
|
||
private static SelectQuery<Row>? QueryCache; | ||
|
||
private static SelectQuery<Row> GetQuery() | ||
{ | ||
if (QueryCache == null) QueryCache = new SelectQuery<Row>(CommandText); | ||
return QueryCache; | ||
} | ||
|
||
public readonly record struct Row( | ||
int a_id, | ||
string text, | ||
int value | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters