This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PgSql.Param API for easily creating NpgsqlParameter's
- Loading branch information
Showing
3 changed files
with
83 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Npgsql; | ||
|
||
namespace ServiceStack.OrmLite.PostgreSQL | ||
{ | ||
public static class PgSql | ||
{ | ||
public static NpgsqlParameter Param<T>(string name, T value) => | ||
new NpgsqlParameter(name, PostgreSqlDialect.Instance.GetDbType<T>()) { | ||
Value = 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
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,18 @@ | ||
using NpgsqlTypes; | ||
using NUnit.Framework; | ||
|
||
namespace ServiceStack.OrmLite.PostgreSQL.Tests | ||
{ | ||
public class PgSqlTests | ||
{ | ||
[Test] | ||
public void Can_create_NpgsqlParameter() | ||
{ | ||
Assert.That(PgSql.Param("p", 1).NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Integer)); | ||
Assert.That(PgSql.Param("p", "s").NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Text)); | ||
Assert.That(PgSql.Param("p", 'c').NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Char)); | ||
Assert.That(PgSql.Param("p", new [] { 1 }).NpgsqlDbType, | ||
Is.EqualTo(NpgsqlDbType.Integer | NpgsqlDbType.Array)); | ||
} | ||
} | ||
} |