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

Commit 90d0266

Browse files
committed
Allow null useDb to unset the db connection
1 parent c0ca11f commit 90d0266

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/ServiceStack.OrmLite/DbScripts.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public IDbConnection OpenDbConnection(ScriptScopeContext scope, Dictionary<strin
4141

4242
public IgnoreResult useDb(ScriptScopeContext scope, Dictionary<string, object> dbConnOptions)
4343
{
44-
if (dbConnOptions != null)
44+
if (dbConnOptions == null)
45+
{
46+
scope.PageResult.Args.Remove(DbConnection);
47+
}
48+
else
4549
{
4650
if (!dbConnOptions.ContainsKey("connectionString") && !dbConnOptions.ContainsKey("namedConnection"))
4751
throw new NotSupportedException(nameof(useDb) + " requires either 'connectionString' or 'namedConnection' property");

src/ServiceStack.OrmLite/DbScriptsAsync.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using ServiceStack.Data;
66
using ServiceStack.Script;
7+
using ServiceStack.Text;
78

89
namespace ServiceStack.OrmLite
910
{
@@ -42,7 +43,11 @@ public async Task<IDbConnection> OpenDbConnectionAsync(ScriptScopeContext scope,
4243

4344
public IgnoreResult useDb(ScriptScopeContext scope, Dictionary<string, object> dbConnOptions)
4445
{
45-
if (dbConnOptions != null)
46+
if (dbConnOptions == null)
47+
{
48+
scope.PageResult.Args.Remove(DbConnection);
49+
}
50+
else
4651
{
4752
if (!dbConnOptions.ContainsKey("connectionString") && !dbConnOptions.ContainsKey("namedConnection"))
4853
throw new NotSupportedException(nameof(useDb) + " requires either 'connectionString' or 'namedConnection' property");

0 commit comments

Comments
 (0)