Skip to content

Commit 15734c3

Browse files
committed
Change to IDatabase
1 parent 7d3af72 commit 15734c3

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

StaTypPocoQueries.PetaPoco/DatabaseExtensions.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ namespace PetaPoco
3131
{
3232
public static class DatabaseExtensions
3333
{
34-
private static Sql ToSql<T>(this Expression<Func<T, bool>> query, Database db)
34+
private static Sql ToSql<T>(this Expression<Func<T, bool>> query, IDatabase db)
3535
{
3636
var translated = ExpressionToSql.Translate(new DatabaseQuoter(db), query);
3737
return new Sql(translated.Item1, translated.Item2);
3838
}
3939

40-
private static Sql ToSql<T>(this FSharpExpr<FSharpFunc<T, bool>> query, Database db)
40+
private static Sql ToSql<T>(this FSharpExpr<FSharpFunc<T, bool>> query, IDatabase db)
4141
{
4242
var translated = ExpressionToSql.Translate(new DatabaseQuoter(db), query);
4343
return new Sql(translated.Item1, translated.Item2);
@@ -51,7 +51,7 @@ private static Sql ToSql<T>(this FSharpExpr<FSharpFunc<T, bool>> query, Database
5151
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
5252
/// <param name="query">An Expression describing the records to be retrieved."/> </param>
5353
/// <returns>A List holding the results of the query</returns>
54-
public static List<T> Fetch<T>(this Database db, Expression<Func<T, bool>> query)
54+
public static List<T> Fetch<T>(this IDatabase db, Expression<Func<T, bool>> query)
5555
=> db.Fetch<T>(query.ToSql(db));
5656

5757
/// <summary>
@@ -67,7 +67,7 @@ public static List<T> Fetch<T>(this Database db, Expression<Func<T, bool>> query
6767
/// records for the specified page. It will also execute a second query to retrieve the
6868
/// total number of records in the result set.
6969
/// </remarks>
70-
public static Page<T> Page<T>(this Database db, long page, long itemsPerPage, Expression<Func<T, bool>> query)
70+
public static Page<T> Page<T>(this IDatabase db, long page, long itemsPerPage, Expression<Func<T, bool>> query)
7171
=> db.Page<T>(page, itemsPerPage, query.ToSql(db));
7272

7373
/// <summary>
@@ -82,7 +82,7 @@ public static Page<T> Page<T>(this Database db, long page, long itemsPerPage, Ex
8282
/// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the
8383
/// records for the specified page.
8484
/// </remarks>
85-
public static List<T> Fetch<T>(this Database db, long page, long itemsPerPage, Expression<Func<T, bool>> query)
85+
public static List<T> Fetch<T>(this IDatabase db, long page, long itemsPerPage, Expression<Func<T, bool>> query)
8686
=> db.Fetch<T>(page, itemsPerPage, query.ToSql(db));
8787

8888
/// <summary>
@@ -97,7 +97,7 @@ public static List<T> Fetch<T>(this Database db, long page, long itemsPerPage, E
9797
/// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the
9898
/// records for the specified range.
9999
/// </remarks>
100-
public static List<T> SkipTake<T>(this Database db, long skip, long take, Expression<Func<T, bool>> query)
100+
public static List<T> SkipTake<T>(this IDatabase db, long skip, long take, Expression<Func<T, bool>> query)
101101
=> db.SkipTake<T>(skip, take, query.ToSql(db));
102102

103103
/// <summary>
@@ -111,7 +111,7 @@ public static List<T> SkipTake<T>(this Database db, long skip, long take, Expres
111111
/// and disposing the previous one. In cases where this is an issue, consider using Fetch which
112112
/// returns the results as a List rather than an IEnumerable.
113113
/// </remarks>
114-
public static IEnumerable<T> Query<T>(this Database db, Expression<Func<T, bool>> query)
114+
public static IEnumerable<T> Query<T>(this IDatabase db, Expression<Func<T, bool>> query)
115115
=> db.Query<T>(query.ToSql(db));
116116

117117
/// <summary>
@@ -123,7 +123,7 @@ public static IEnumerable<T> Query<T>(this Database db, Expression<Func<T, bool>
123123
/// <remarks>
124124
/// Throws an exception if there are zero or more than one matching record
125125
/// </remarks>
126-
public static T Single<T>(this Database db, Expression<Func<T, bool>> query)
126+
public static T Single<T>(this IDatabase db, Expression<Func<T, bool>> query)
127127
=> db.Single<T>(query.ToSql(db));
128128

129129
/// <summary>
@@ -132,7 +132,7 @@ public static T Single<T>(this Database db, Expression<Func<T, bool>> query)
132132
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
133133
/// <param name="query">An Expression describing the record to be retrieved."/> </param>
134134
/// <returns>The single record matching the specified condition, or default(T) if no matching rows</returns>
135-
public static T SingleOrDefault<T>(this Database db, Expression<Func<T, bool>> query)
135+
public static T SingleOrDefault<T>(this IDatabase db, Expression<Func<T, bool>> query)
136136
=> db.SingleOrDefault<T>(query.ToSql(db));
137137

138138
/// <summary>
@@ -141,7 +141,7 @@ public static T SingleOrDefault<T>(this Database db, Expression<Func<T, bool>> q
141141
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
142142
/// <param name="query">An Expression describing the records to be retrieved."/> </param>
143143
/// <returns>The first record in the result set</returns>
144-
public static T First<T>(this Database db, Expression<Func<T, bool>> query)
144+
public static T First<T>(this IDatabase db, Expression<Func<T, bool>> query)
145145
=> db.First<T>(query.ToSql(db));
146146

147147
/// <summary>
@@ -150,7 +150,7 @@ public static T First<T>(this Database db, Expression<Func<T, bool>> query)
150150
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
151151
/// <param name="query">An Expression describing the records to be retrieved."/> </param>
152152
/// <returns>The first record in the result set, or default(T) if no matching rows</returns>
153-
public static T FirstOrDefault<T>(this Database db, Expression<Func<T, bool>> query)
153+
public static T FirstOrDefault<T>(this IDatabase db, Expression<Func<T, bool>> query)
154154
=> db.FirstOrDefault<T>(query.ToSql(db));
155155

156156
/// <summary>
@@ -162,7 +162,7 @@ public static T FirstOrDefault<T>(this Database db, Expression<Func<T, bool>> qu
162162
/// everything after "DELETE FROM tablename"
163163
/// </param>
164164
/// <returns>The number of affected rows</returns>
165-
public static int Delete<T>(this Database db, Expression<Func<T, bool>> query)
165+
public static int Delete<T>(this IDatabase db, Expression<Func<T, bool>> query)
166166
=> db.Delete<T>(query.ToSql(db));
167167
#endregion
168168

@@ -173,7 +173,7 @@ public static int Delete<T>(this Database db, Expression<Func<T, bool>> query)
173173
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
174174
/// <param name="query">An Expression describing the records to be retrieved."/> </param>
175175
/// <returns>A List holding the results of the query</returns>
176-
public static List<T> Fetch<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query)
176+
public static List<T> Fetch<T>(this IDatabase db, FSharpExpr<FSharpFunc<T, bool>> query)
177177
=> db.Fetch<T>(query.ToSql(db));
178178

179179
/// <summary>
@@ -189,7 +189,7 @@ public static List<T> Fetch<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>>
189189
/// records for the specified page. It will also execute a second query to retrieve the
190190
/// total number of records in the result set.
191191
/// </remarks>
192-
public static Page<T> Page<T>(this Database db, long page, long itemsPerPage, FSharpExpr<FSharpFunc<T, bool>> query)
192+
public static Page<T> Page<T>(this IDatabase db, long page, long itemsPerPage, FSharpExpr<FSharpFunc<T, bool>> query)
193193
=> db.Page<T>(page, itemsPerPage, query.ToSql(db));
194194

195195
/// <summary>
@@ -204,7 +204,7 @@ public static Page<T> Page<T>(this Database db, long page, long itemsPerPage, FS
204204
/// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the
205205
/// records for the specified page.
206206
/// </remarks>
207-
public static List<T> Fetch<T>(this Database db, long page, long itemsPerPage, FSharpExpr<FSharpFunc<T, bool>> query)
207+
public static List<T> Fetch<T>(this IDatabase db, long page, long itemsPerPage, FSharpExpr<FSharpFunc<T, bool>> query)
208208
=> db.Fetch<T>(page, itemsPerPage, query.ToSql(db));
209209

210210
/// <summary>
@@ -219,7 +219,7 @@ public static List<T> Fetch<T>(this Database db, long page, long itemsPerPage, F
219219
/// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the
220220
/// records for the specified range.
221221
/// </remarks>
222-
public static List<T> SkipTake<T>(this Database db, long skip, long take, FSharpExpr<FSharpFunc<T, bool>> query)
222+
public static List<T> SkipTake<T>(this IDatabase db, long skip, long take, FSharpExpr<FSharpFunc<T, bool>> query)
223223
=> db.SkipTake<T>(skip, take, query.ToSql(db));
224224

225225
/// <summary>
@@ -233,7 +233,7 @@ public static List<T> SkipTake<T>(this Database db, long skip, long take, FSharp
233233
/// and disposing the previous one. In cases where this is an issue, consider using Fetch which
234234
/// returns the results as a List rather than an IEnumerable.
235235
/// </remarks>
236-
public static IEnumerable<T> Query<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query)
236+
public static IEnumerable<T> Query<T>(this IDatabase db, FSharpExpr<FSharpFunc<T, bool>> query)
237237
=> db.Query<T>(query.ToSql(db));
238238

239239
/// <summary>
@@ -245,7 +245,7 @@ public static IEnumerable<T> Query<T>(this Database db, FSharpExpr<FSharpFunc<T,
245245
/// <remarks>
246246
/// Throws an exception if there are zero or more than one matching record
247247
/// </remarks>
248-
public static T Single<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query)
248+
public static T Single<T>(this IDatabase db, FSharpExpr<FSharpFunc<T, bool>> query)
249249
=> db.Single<T>(query.ToSql(db));
250250

251251
/// <summary>
@@ -254,7 +254,7 @@ public static T Single<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> quer
254254
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
255255
/// <param name="query">An Expression describing the record to be retrieved."/> </param>
256256
/// <returns>The single record matching the specified condition, or default(T) if no matching rows</returns>
257-
public static T SingleOrDefault<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query)
257+
public static T SingleOrDefault<T>(this IDatabase db, FSharpExpr<FSharpFunc<T, bool>> query)
258258
=> db.SingleOrDefault<T>(query.ToSql(db));
259259

260260
/// <summary>
@@ -263,7 +263,7 @@ public static T SingleOrDefault<T>(this Database db, FSharpExpr<FSharpFunc<T, bo
263263
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
264264
/// <param name="query">An Expression describing the records to be retrieved."/> </param>
265265
/// <returns>The first record in the result set</returns>
266-
public static T First<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query)
266+
public static T First<T>(this IDatabase db, FSharpExpr<FSharpFunc<T, bool>> query)
267267
=> db.First<T>(query.ToSql(db));
268268

269269
/// <summary>
@@ -272,7 +272,7 @@ public static T First<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query
272272
/// <typeparam name="T">The Type representing a row in the result set</typeparam>
273273
/// <param name="query">An Expression describing the records to be retrieved."/> </param>
274274
/// <returns>The first record in the result set, or default(T) if no matching rows</returns>
275-
public static T FirstOrDefault<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query)
275+
public static T FirstOrDefault<T>(this IDatabase db, FSharpExpr<FSharpFunc<T, bool>> query)
276276
=> db.FirstOrDefault<T>(query.ToSql(db));
277277

278278
/// <summary>
@@ -284,7 +284,7 @@ public static T FirstOrDefault<T>(this Database db, FSharpExpr<FSharpFunc<T, boo
284284
/// everything after "DELETE FROM tablename"
285285
/// </param>
286286
/// <returns>The number of affected rows</returns>
287-
public static int Delete<T>(this Database db, FSharpExpr<FSharpFunc<T, bool>> query)
287+
public static int Delete<T>(this IDatabase db, FSharpExpr<FSharpFunc<T, bool>> query)
288288
=> db.Delete<T>(query.ToSql(db));
289289
#endregion
290290
}

StaTypPocoQueries.PetaPoco/DatabaseQuoter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ namespace StaTypPocoQueries.PetaPoco
2626
{
2727
public class DatabaseQuoter: Translator.IQuoter
2828
{
29-
private readonly Database _db;
29+
private readonly IDatabase _db;
3030

31-
public DatabaseQuoter(Database db)
31+
public DatabaseQuoter(IDatabase db)
3232
{
3333
_db = db;
3434
}

StaTypPocoQueries.PetaPoco/StaTypPocoQueries.PetaPoco.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
88
<Description>PetaPoco bindings for StaTypPocoQueries.</Description>
99
<Authors>Aaron Sherber</Authors>
10-
<Copyright>Copyright 2018</Copyright>
10+
<Copyright>Copyright 2018-19</Copyright>
1111
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1212
<RepositoryUrl>https://github.com/asherber/StaTypPocoQueries.PetaPoco</RepositoryUrl>
1313
<RepositoryType>git</RepositoryType>
1414
<PackageIconUrl>https://raw.githubusercontent.com/asherber/StaTypPocoQueries.PetaPoco/master/media/static-64.png</PackageIconUrl>
1515
<PackageTags>petapoco statyppocoqueries statically typed</PackageTags>
16-
<PackageReleaseNotes>Use published StaTypPocoQueries instead of private build.</PackageReleaseNotes>
16+
<PackageReleaseNotes>Extension methods now use IDatabase instead of Database</PackageReleaseNotes>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

StaTypPocoQueries.PetaPoco/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.1",
2+
"version": "1.2",
33
"publicReleaseRefSpec": [
44
"^refs/heads/master$",
55
"^refs/heads/v\\d+(?:\\.\\d+)?$"

0 commit comments

Comments
 (0)