Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 2438aeb

Browse files
committed
Deprecate TemplateDbFilters/Async + add DbScripts/DbScriptsAsync
1 parent 8b9c78c commit 2438aeb

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

src/ServiceStack.OrmLite/TemplateDbFilters.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using ServiceStack.Data;
5-
using ServiceStack.Templates;
5+
using ServiceStack.Script;
66

77
namespace ServiceStack.OrmLite
88
{
9-
public class TemplateDbFilters : TemplateFilter
9+
[Obsolete("Use DbScripts")]
10+
public class TemplateDbFilters : DbScripts {}
11+
12+
public class DbScripts : ScriptMethods
1013
{
1114
private IDbConnectionFactory dbFactory;
1215
public IDbConnectionFactory DbFactory
@@ -15,7 +18,7 @@ public IDbConnectionFactory DbFactory
1518
set => dbFactory = value;
1619
}
1720

18-
public IDbConnection OpenDbConnection(TemplateScopeContext scope, Dictionary<string, object> options)
21+
public IDbConnection OpenDbConnection(ScriptScopeContext scope, Dictionary<string, object> options)
1922
{
2023
if (options != null)
2124
{
@@ -34,7 +37,7 @@ public IDbConnection OpenDbConnection(TemplateScopeContext scope, Dictionary<str
3437
return DbFactory.OpenDbConnection();
3538
}
3639

37-
T exec<T>(Func<IDbConnection, T> fn, TemplateScopeContext scope, object options)
40+
T exec<T>(Func<IDbConnection, T> fn, ScriptScopeContext scope, object options)
3841
{
3942
try
4043
{
@@ -49,43 +52,43 @@ T exec<T>(Func<IDbConnection, T> fn, TemplateScopeContext scope, object options)
4952
}
5053
}
5154

52-
public object dbSelect(TemplateScopeContext scope, string sql) =>
55+
public object dbSelect(ScriptScopeContext scope, string sql) =>
5356
exec(db => db.SqlList<Dictionary<string, object>>(sql), scope, null);
5457

55-
public object dbSelect(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
58+
public object dbSelect(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
5659
exec(db => db.SqlList<Dictionary<string, object>>(sql, args), scope, null);
5760

58-
public object dbSelect(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
61+
public object dbSelect(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
5962
exec(db => db.SqlList<Dictionary<string, object>>(sql, args), scope, options);
6063

6164

62-
public object dbSingle(TemplateScopeContext scope, string sql) =>
65+
public object dbSingle(ScriptScopeContext scope, string sql) =>
6366
exec(db => db.Single<Dictionary<string, object>>(sql), scope, null);
6467

65-
public object dbSingle(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
68+
public object dbSingle(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
6669
exec(db => db.Single<Dictionary<string, object>>(sql, args), scope, null);
6770

68-
public object dbSingle(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
71+
public object dbSingle(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
6972
exec(db => db.Single<Dictionary<string, object>>(sql, args), scope, options);
7073

7174

72-
public object dbScalar(TemplateScopeContext scope, string sql) =>
75+
public object dbScalar(ScriptScopeContext scope, string sql) =>
7376
exec(db => db.Scalar<object>(sql), scope, null);
7477

75-
public object dbScalar(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
78+
public object dbScalar(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
7679
exec(db => db.Scalar<object>(sql, args), scope, null);
7780

78-
public object dbScalar(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
81+
public object dbScalar(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
7982
exec(db => db.Scalar<object>(sql, args), scope, options);
8083

8184

82-
public int dbExec(TemplateScopeContext scope, string sql) =>
85+
public int dbExec(ScriptScopeContext scope, string sql) =>
8386
exec(db => db.ExecuteSql(sql), scope, null);
8487

85-
public int dbExec(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
88+
public int dbExec(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
8689
exec(db => db.ExecuteSql(sql, args), scope, null);
8790

88-
public int dbExec(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
91+
public int dbExec(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
8992
exec(db => db.ExecuteSql(sql, args), scope, options);
9093

9194

src/ServiceStack.OrmLite/TemplateDbFiltersAsync.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
using System.Data;
44
using System.Threading.Tasks;
55
using ServiceStack.Data;
6-
using ServiceStack.Templates;
6+
using ServiceStack.Script;
77

88
namespace ServiceStack.OrmLite
99
{
10-
public class TemplateDbFiltersAsync : TemplateFilter
10+
[Obsolete("Use DbScriptsAsync")]
11+
public class TemplateDbFiltersAsync : DbScriptsAsync {}
12+
13+
public class DbScriptsAsync : ScriptMethods
1114
{
1215
private IDbConnectionFactory dbFactory;
1316
public IDbConnectionFactory DbFactory
@@ -16,7 +19,7 @@ public IDbConnectionFactory DbFactory
1619
set => dbFactory = value;
1720
}
1821

19-
public async Task<IDbConnection> OpenDbConnectionAsync(TemplateScopeContext scope, Dictionary<string, object> options)
22+
public async Task<IDbConnection> OpenDbConnectionAsync(ScriptScopeContext scope, Dictionary<string, object> options)
2023
{
2124
if (options != null)
2225
{
@@ -35,7 +38,7 @@ public async Task<IDbConnection> OpenDbConnectionAsync(TemplateScopeContext scop
3538
return await DbFactory.OpenAsync();
3639
}
3740

38-
async Task<object> exec<T>(Func<IDbConnection, Task<T>> fn, TemplateScopeContext scope, object options)
41+
async Task<object> exec<T>(Func<IDbConnection, Task<T>> fn, ScriptScopeContext scope, object options)
3942
{
4043
try
4144
{
@@ -51,43 +54,43 @@ async Task<object> exec<T>(Func<IDbConnection, Task<T>> fn, TemplateScopeContext
5154
}
5255
}
5356

54-
public Task<object> dbSelect(TemplateScopeContext scope, string sql) =>
57+
public Task<object> dbSelect(ScriptScopeContext scope, string sql) =>
5558
exec(db => db.SqlListAsync<Dictionary<string, object>>(sql), scope, null);
5659

57-
public Task<object> dbSelect(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
60+
public Task<object> dbSelect(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
5861
exec(db => db.SqlListAsync<Dictionary<string, object>>(sql, args), scope, null);
5962

60-
public Task<object> dbSelect(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
63+
public Task<object> dbSelect(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
6164
exec(db => db.SqlListAsync<Dictionary<string, object>>(sql, args), scope, options);
6265

6366

64-
public Task<object> dbSingle(TemplateScopeContext scope, string sql) =>
67+
public Task<object> dbSingle(ScriptScopeContext scope, string sql) =>
6568
exec(db => db.SingleAsync<Dictionary<string, object>>(sql), scope, null);
6669

67-
public Task<object> dbSingle(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
70+
public Task<object> dbSingle(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
6871
exec(db => db.SingleAsync<Dictionary<string, object>>(sql, args), scope, null);
6972

70-
public Task<object> dbSingle(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
73+
public Task<object> dbSingle(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
7174
exec(db => db.SingleAsync<Dictionary<string, object>>(sql, args), scope, options);
7275

7376

74-
public Task<object> dbScalar(TemplateScopeContext scope, string sql) =>
77+
public Task<object> dbScalar(ScriptScopeContext scope, string sql) =>
7578
exec(db => db.ScalarAsync<object>(sql), scope, null);
7679

77-
public Task<object> dbScalar(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
80+
public Task<object> dbScalar(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
7881
exec(db => db.ScalarAsync<object>(sql, args), scope, null);
7982

80-
public Task<object> dbScalar(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
83+
public Task<object> dbScalar(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
8184
exec(db => db.ScalarAsync<object>(sql, args), scope, options);
8285

8386

84-
public Task<object> dbExec(TemplateScopeContext scope, string sql) =>
87+
public Task<object> dbExec(ScriptScopeContext scope, string sql) =>
8588
exec(db => db.ExecuteSqlAsync(sql), scope, null);
8689

87-
public Task<object> dbExec(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
90+
public Task<object> dbExec(ScriptScopeContext scope, string sql, Dictionary<string, object> args) =>
8891
exec(db => db.ExecuteSqlAsync(sql, args), scope, null);
8992

90-
public Task<object> dbExec(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
93+
public Task<object> dbExec(ScriptScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
9194
exec(db => db.ExecuteSqlAsync(sql, args), scope, options);
9295

9396

0 commit comments

Comments
 (0)