Last active
August 29, 2015 14:19
-
-
Save yreynhout/40f0f940bd8ca1fa4c4d to your computer and use it in GitHub Desktop.
Projac Syntax v2
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
using System; | |
using System.Net; | |
using NUnit.Framework; | |
using Projac.Redis; | |
using Recipes.Shared; | |
using StackExchange.Redis; | |
namespace Recipes.RedisIntegration | |
{ | |
public class Usage | |
{ | |
public static RedisProjection Projection = new RedisProjectionBuilder(). | |
When<PortfolioAdded>((connection, message) => | |
{ | |
var db = connection.GetDatabase(); | |
return db.HashSetAsync(message.Id.ToString("N"), "Name", message.Name); | |
}). | |
When<PortfolioRemoved>((connection, message) => | |
{ | |
var db = connection.GetDatabase(); | |
return db.HashDeleteAsync(message.Id.ToString("N"), "Name"); | |
}). | |
When<PortfolioRenamed>((connection, message) => | |
{ | |
var db = connection.GetDatabase(); | |
return db.HashSetAsync(message.Id.ToString("N"), "Name", message.Name); | |
}). | |
Build(); | |
public class PortfolioProjection : RedisProjection2 | |
{ | |
public PortfolioProjection() | |
{ | |
When<PortfolioAdded>((connection, message) => | |
{ | |
var db = connection.GetDatabase(); | |
return db.HashSetAsync(message.Id.ToString("N"), "Name", message.Name); | |
}); | |
When<PortfolioRemoved>((connection, message) => | |
{ | |
var db = connection.GetDatabase(); | |
return db.HashDeleteAsync(message.Id.ToString("N"), "Name"); | |
}); | |
When<PortfolioRenamed>((connection, message) => | |
{ | |
var db = connection.GetDatabase(); | |
return db.HashSetAsync(message.Id.ToString("N"), "Name", message.Name); | |
}); | |
} | |
} | |
} | |
} |
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
using Paramol.SqlClient; | |
using Projac; | |
using Recipes.Shared; | |
namespace Recipes.Sql | |
{ | |
public static class Usage | |
{ | |
public static readonly SqlProjection Portfolio = new SqlProjectionBuilder(). | |
When<PortfolioAdded>(@event => | |
TSql.NonQueryStatement( | |
"INSERT INTO [Portfolio] ([Id], [Name], [PhotoCount]) VALUES (@P1, @P2, 0)", | |
new { P1 = TSql.UniqueIdentifier(@event.Id), P2 = TSql.NVarChar(@event.Name, 40) } | |
)). | |
When<PortfolioRemoved>(@event => | |
TSql.NonQueryStatement( | |
"DELETE FROM [Portfolio] WHERE [Id] = @P1", | |
new { P1 = TSql.UniqueIdentifier(@event.Id) } | |
)). | |
When<PortfolioRenamed>(@event => | |
TSql.NonQueryStatement( | |
"UPDATE [Portfolio] SET [Name] = @P2 WHERE [Id] = @P1", | |
new { P1 = TSql.UniqueIdentifier(@event.Id), P2 = TSql.NVarChar(@event.Name, 40) } | |
)). | |
Build(); | |
public class PortfolioProjection : SqlProjection2 | |
{ | |
public PortfolioProjection() | |
{ | |
When<PortfolioAdded>(@event => | |
TSql.NonQueryStatement( | |
"INSERT INTO [Portfolio] ([Id], [Name], [PhotoCount]) VALUES (@P1, @P2, 0)", | |
new {P1 = TSql.UniqueIdentifier(@event.Id), P2 = TSql.NVarChar(@event.Name, 40)} | |
)); | |
When<PortfolioRemoved>(@event => | |
TSql.NonQueryStatement( | |
"DELETE FROM [Portfolio] WHERE [Id] = @P1", | |
new {P1 = TSql.UniqueIdentifier(@event.Id)} | |
)); | |
When<PortfolioRenamed>(@event => | |
TSql.NonQueryStatement( | |
"UPDATE [Portfolio] SET [Name] = @P2 WHERE [Id] = @P1", | |
new {P1 = TSql.UniqueIdentifier(@event.Id), P2 = TSql.NVarChar(@event.Name, 40)} | |
)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment