Skip to content

Instantly share code, notes, and snippets.

@yreynhout
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yreynhout/40f0f940bd8ca1fa4c4d to your computer and use it in GitHub Desktop.
Save yreynhout/40f0f940bd8ca1fa4c4d to your computer and use it in GitHub Desktop.
Projac Syntax v2
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);
});
}
}
}
}
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