Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
4153d2d8
Commit
4153d2d8
authored
Sep 15, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #162 from jbattermann/master
Added async/await to Dapper.Rainbow - .Net 4.5 Hooray \o/
parents
4bfa979d
90a28dc4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
219 additions
and
10 deletions
+219
-10
Dapper - VS2012.sln
Dapper - VS2012.sln
+13
-0
Dapper.Rainbow NET45.csproj
Dapper.Rainbow NET45/Dapper.Rainbow NET45.csproj
+71
-0
DatabaseAsync.cs
Dapper.Rainbow NET45/DatabaseAsync.cs
+127
-0
Dapper.Rainbow.nuspec
Dapper.Rainbow.nuspec
+6
-3
Dapper.Rainbow.csproj
Dapper.Rainbow/Dapper.Rainbow.csproj
+0
-5
Database.cs
Dapper.Rainbow/Database.cs
+2
-2
No files found.
Dapper - VS2012.sln
View file @
4153d2d8
...
...
@@ -31,6 +31,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Dapper.Contrib.nuspec = Dapper.Contrib.nuspec
Dapper.EntityFramework.nuspec = Dapper.EntityFramework.nuspec
Dapper.nuspec = Dapper.nuspec
Dapper.Rainbow.nuspec = Dapper.Rainbow.nuspec
License.txt = License.txt
EndProjectSection
EndProject
...
...
@@ -42,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.EntityFramework NET4
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.Contrib NET45", "Dapper.Contrib NET45\Dapper.Contrib NET45.csproj", "{302EC82F-A81B-48C5-B653-B5C75D2BD103}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.Rainbow NET45", "Dapper.Rainbow NET45\Dapper.Rainbow NET45.csproj", "{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -182,6 +185,16 @@ Global
{302EC82F-A81B-48C5-B653-B5C75D2BD103}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{302EC82F-A81B-48C5-B653-B5C75D2BD103}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{302EC82F-A81B-48C5-B653-B5C75D2BD103}.Release|x86.ActiveCfg = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|x86.ActiveCfg = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Any CPU.Build.0 = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
Dapper.Rainbow NET45/Dapper.Rainbow NET45.csproj
0 → 100644
View file @
4153d2d8
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"12.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Import
Project=
"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition=
"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
/>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProjectGuid>
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
Dapper.Rainbow
</RootNamespace>
<AssemblyName>
Dapper.Rainbow
</AssemblyName>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE;ASYNC
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE;ASYNC
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.XML"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"..\Dapper.Rainbow\Database.cs"
>
<Link>
Database.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\IgnorePropertyAttribute.cs"
>
<Link>
IgnorePropertyAttribute.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\Properties\AssemblyInfo.cs"
>
<Link>
Properties\AssemblyInfo.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\Snapshotter.cs"
>
<Link>
Snapshotter.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\SqlCompactDatabase.cs"
>
<Link>
SqlCompactDatabase.cs
</Link>
</Compile>
<Compile
Include=
"DatabaseAsync.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Dapper NET45\Dapper NET45.csproj"
>
<Project>
{0fff5bc7-0a4b-4d87-835e-4fad70937507}
</Project>
<Name>
Dapper NET45
</Name>
</ProjectReference>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
Dapper.Rainbow NET45/DatabaseAsync.cs
0 → 100644
View file @
4153d2d8
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data.Common
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Dapper
{
public
abstract
partial
class
Database
<
TDatabase
>
:
IDisposable
where
TDatabase
:
Database
<
TDatabase
>,
new
()
{
public
partial
class
Table
<
T
,
TId
>
{
/// <summary>
/// Insert a row into the db asynchronously
/// </summary>
/// <param name="data">Either DynamicParameters or an anonymous type or concrete type</param>
/// <returns></returns>
public
virtual
async
Task
<
int
?>
InsertAsync
(
dynamic
data
)
{
var
o
=
(
object
)
data
;
List
<
string
>
paramNames
=
GetParamNames
(
o
);
paramNames
.
Remove
(
"Id"
);
string
cols
=
string
.
Join
(
","
,
paramNames
);
string
cols_params
=
string
.
Join
(
","
,
paramNames
.
Select
(
p
=>
"@"
+
p
));
var
sql
=
"set nocount on insert "
+
TableName
+
" ("
+
cols
+
") values ("
+
cols_params
+
") select cast(scope_identity() as int)"
;
return
(
await
database
.
QueryAsync
<
int
?>(
sql
,
o
)).
Single
();
}
/// <summary>
/// Update a record in the DB asynchronously
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <returns></returns>
public
async
Task
<
int
>
UpdateAsync
(
TId
id
,
dynamic
data
)
{
List
<
string
>
paramNames
=
GetParamNames
((
object
)
data
);
var
builder
=
new
StringBuilder
();
builder
.
Append
(
"update "
).
Append
(
TableName
).
Append
(
" set "
);
builder
.
AppendLine
(
string
.
Join
(
","
,
paramNames
.
Where
(
n
=>
n
!=
"Id"
).
Select
(
p
=>
p
+
"= @"
+
p
)));
builder
.
Append
(
"where Id = @Id"
);
DynamicParameters
parameters
=
new
DynamicParameters
(
data
);
parameters
.
Add
(
"Id"
,
id
);
return
await
database
.
ExecuteAsync
(
builder
.
ToString
(),
parameters
);
}
/// <summary>
/// Delete a record for the DB asynchronously
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public
async
Task
<
bool
>
DeleteAsync
(
TId
id
)
{
return
(
await
database
.
ExecuteAsync
(
"delete from "
+
TableName
+
" where Id = @id"
,
new
{
id
}))
>
0
;
}
/// <summary>
/// Grab a record with a particular Id from the DB asynchronously
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public
async
Task
<
T
>
GetAsync
(
TId
id
)
{
return
(
await
database
.
QueryAsync
<
T
>(
"select * from "
+
TableName
+
" where Id = @id"
,
new
{
id
})).
FirstOrDefault
();
}
public
virtual
async
Task
<
T
>
FirstAsync
()
{
return
(
await
database
.
QueryAsync
<
T
>(
"select top 1 * from "
+
TableName
)).
FirstOrDefault
();
}
public
async
Task
<
IEnumerable
<
T
>>
AllAsync
()
{
return
await
database
.
QueryAsync
<
T
>(
"select * from "
+
TableName
);
}
}
public
async
Task
<
int
>
ExecuteAsync
(
string
sql
,
dynamic
param
=
null
)
{
return
await
connection
.
ExecuteAsync
(
sql
,
param
as
object
,
transaction
,
this
.
commandTimeout
);
}
public
async
Task
<
IEnumerable
<
T
>>
QueryAsync
<
T
>(
string
sql
,
dynamic
param
=
null
)
{
return
await
connection
.
QueryAsync
<
T
>(
sql
,
param
as
object
,
transaction
,
commandTimeout
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TThird
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TThird
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
dynamic
>>
QueryAsync
(
string
sql
,
dynamic
param
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
param
as
object
,
transaction
);
}
public
async
Task
<
SqlMapper
.
GridReader
>
QueryMultipleAsync
(
string
sql
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
CommandType
?
commandType
=
null
)
{
return
await
SqlMapper
.
QueryMultipleAsync
(
connection
,
sql
,
param
,
transaction
,
commandTimeout
,
commandType
);
}
}
}
Dapper.Rainbow
/Dapper.Rainbow
.nuspec
→
Dapper.Rainbow.nuspec
View file @
4153d2d8
...
...
@@ -2,7 +2,7 @@
<package
>
<metadata>
<id>
Dapper.Rainbow
</id>
<version>
0.
1.2
</version>
<version>
0.
2.0
</version>
<title>
Dapper.Rainbow
</title>
<authors>
Sam Saffron
</authors>
<owners>
Sam Saffron
</owners>
...
...
@@ -18,6 +18,8 @@
Data explorer uses "Rainbow" exclusively for all database access.
</summary>
<releaseNotes>
* version 0.2:
.Net 4.5 async/await capability added.
* version 0.1:
A demo is available at https://gist.github.com/1599013 .
The implementation was extracted from http://data.stackexchange.com source at: http://code.google.com/p/stack-exchange-data-explorer/ .
...
...
@@ -26,10 +28,11 @@
<copyright>
Copyright Sam Saffron 2012
</copyright>
<tags>
orm dapper micro-orm
</tags>
<dependencies>
<dependency
id=
"Dapper"
version=
"1.
8
"
/>
<dependency
id=
"Dapper"
version=
"1.
34
"
/>
</dependencies>
</metadata>
<files>
<file
src=
"bin\Release\Dapper.Rainbow.dll"
target=
"lib\net40"
/>
<file
src=
"Dapper.Rainbow NET45\bin\Release\Dapper.Rainbow.*"
target=
"lib\net45"
/>
<file
src=
"Dapper.Rainbow\bin\Release\Dapper.Rainbow.*"
target=
"lib\net40"
/>
</files>
</package>
\ No newline at end of file
Dapper.Rainbow/Dapper.Rainbow.csproj
View file @
4153d2d8
...
...
@@ -46,11 +46,6 @@
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"SqlCompactDatabase.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"Dapper.Rainbow.nuspec"
>
<SubType>
Designer
</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Dapper NET40\Dapper NET40.csproj"
>
<Project>
{daf737e1-05b5-4189-a5aa-dac6233b64d7}
</Project>
...
...
Dapper.Rainbow/Database.cs
View file @
4153d2d8
...
...
@@ -22,9 +22,9 @@ namespace Dapper
/// A container for a database, assumes all the tables have an Id column named Id
/// </summary>
/// <typeparam name="TDatabase"></typeparam>
public
abstract
class
Database
<
TDatabase
>
:
IDisposable
where
TDatabase
:
Database
<
TDatabase
>,
new
()
public
abstract
partial
class
Database
<
TDatabase
>
:
IDisposable
where
TDatabase
:
Database
<
TDatabase
>,
new
()
{
public
class
Table
<
T
,
TId
>
public
partial
class
Table
<
T
,
TId
>
{
internal
Database
<
TDatabase
>
database
;
internal
string
tableName
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment