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

Commit dbf9777

Browse files
committed
Update TemplateDbFilters
1 parent cba6ee5 commit dbf9777

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

src/ServiceStack.OrmLite/TemplateDbFilters.cs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,61 @@ namespace ServiceStack.OrmLite
99
public class TemplateDbFilters : TemplateFilter
1010
{
1111
public IDbConnectionFactory DbFactory { get; set; }
12-
T exec<T>(Func<IDbConnection, T> fn)
12+
13+
T exec<T>(Func<IDbConnection, T> fn, TemplateScopeContext scope, object options)
1314
{
14-
using (var db = DbFactory.Open())
15+
try
16+
{
17+
using (var db = DbFactory.Open())
18+
{
19+
return fn(db);
20+
}
21+
}
22+
catch (Exception ex)
1523
{
16-
return fn(db);
24+
throw new StopFilterExecutionException(scope, options, ex);
1725
}
1826
}
1927

20-
public object dbSelect(string sql) => exec(db => db.Select<Dictionary<string, object>>(sql));
21-
public object dbSelect(string sql, Dictionary<string, object> args) => exec(db => db.Select<Dictionary<string, object>>(sql, args));
22-
public object dbSingle(string sql) => exec(db => db.Single<Dictionary<string, object>>(sql));
23-
public object dbSingle(string sql, Dictionary<string, object> args) => exec(db => db.Single<Dictionary<string, object>>(sql, args));
24-
public object dbScalar(string sql) => exec(db => db.Scalar<object>(sql));
25-
public object dbScalar(string sql, Dictionary<string, object> args) => exec(db => db.Scalar<object>(sql, args));
26-
public int dbExec(string sql, Dictionary<string, object> args) => exec(db => db.ExecuteSql(sql, args));
28+
public object dbSelect(TemplateScopeContext scope, string sql) =>
29+
exec(db => db.Select<Dictionary<string, object>>(sql), scope, null);
30+
31+
public object dbSelect(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
32+
exec(db => db.Select<Dictionary<string, object>>(sql, args), scope, null);
33+
34+
public object dbSelect(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
35+
exec(db => db.Select<Dictionary<string, object>>(sql, args), scope, options);
36+
37+
38+
public object dbSingle(TemplateScopeContext scope, string sql) =>
39+
exec(db => db.Single<Dictionary<string, object>>(sql), scope, null);
40+
41+
public object dbSingle(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
42+
exec(db => db.Single<Dictionary<string, object>>(sql, args), scope, null);
43+
44+
public object dbSingle(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
45+
exec(db => db.Single<Dictionary<string, object>>(sql, args), scope, options);
46+
47+
48+
public object dbScalar(TemplateScopeContext scope, string sql) =>
49+
exec(db => db.Scalar<object>(sql), scope, null);
50+
51+
public object dbScalar(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
52+
exec(db => db.Scalar<object>(sql, args), scope, null);
53+
54+
public object dbScalar(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
55+
exec(db => db.Scalar<object>(sql, args), scope, options);
56+
57+
58+
public int dbExec(TemplateScopeContext scope, string sql) =>
59+
exec(db => db.ExecuteSql(sql), scope, null);
60+
61+
public int dbExec(TemplateScopeContext scope, string sql, Dictionary<string, object> args) =>
62+
exec(db => db.ExecuteSql(sql, args), scope, null);
63+
64+
public int dbExec(TemplateScopeContext scope, string sql, Dictionary<string, object> args, object options) =>
65+
exec(db => db.ExecuteSql(sql, args), scope, options);
66+
2767

2868
public string sqlQuote(string name) => OrmLiteConfig.DialectProvider.GetQuotedName(name);
2969
public string sqlConcat(IEnumerable<object> values) => OrmLiteConfig.DialectProvider.SqlConcat(values);

0 commit comments

Comments
 (0)