Skip to content

Commit

Permalink
Simplify postgresql samples (#6943)
Browse files Browse the repository at this point in the history
* Simplify snippets by relying on docker

* Cleanup sample description

* Change the include (let's see if include in include works)

* Some spacing for better reability

* remove unnecessary named param

* Further cleanup of transition sample to be aligned

* Simplify lambda

* Simplify lambda

---------

Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
Co-authored-by: Mauro Servienti <mauro.servienti@gmail.com>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent ac22f16 commit f9e807b
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(connectionBuilder: () => new SqlConnection(connectionString));
persistence.ConnectionBuilder(() => new SqlConnection(connectionString));

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(connectionBuilder: () => new SqlConnection(connectionString));
persistence.ConnectionBuilder(() => new SqlConnection(connectionString));

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Apply(EndpointConfiguration endpointConfiguration)
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistenceRenameSaga;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
() => new SqlConnection(connectionString));

endpointConfiguration.EnableInstallers();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Apply(EndpointConfiguration endpointConfiguration)
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistenceRenameSaga;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
() => new SqlConnection(connectionString));

endpointConfiguration.EnableInstallers();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,21 @@

Console.Title = "EndpointMySql";

#region MySqlConfig

var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region MySqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("MySqlPassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("MySqlUserName");
if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
}
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
persistence.SqlDialect<SqlDialect.MySql>();
persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new MySqlConnection(connection);
});
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

var connection = "server=localhost;user=root;database=sqlpersistencesample;port=3306;password=yourStrong(!)Password;AllowUserVariables=True;AutoEnlist=false";

persistence.ConnectionBuilder(() => new MySqlConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand All @@ -43,4 +29,4 @@
Console.WriteLine("Press any key to exit");
Console.ReadKey();

await endpointInstance.Stop();
await endpointInstance.Stop();
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,21 @@

Console.Title = "EndpointOracle";

#region OracleConfig

var endpointConfiguration = new EndpointConfiguration("EndpointOracle");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region OracleConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("OraclePassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'OraclePassword' from Environment variables.");
}

var username = Environment.GetEnvironmentVariable("OracleUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'OracleUserName' from Environment variables.");
}

var connection = $"Data Source=localhost;User Id={username}; Password={password}; Enlist=false";

persistence.SqlDialect<SqlDialect.Oracle>();

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new OracleConnection(connection);
});
var connection = $"Data Source=localhost;User Id=SYSTEM; Password=yourStrong(!)Password; Enlist=false";

persistence.ConnectionBuilder(() => new OracleConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand All @@ -48,4 +28,4 @@
Console.WriteLine("Press any key to exit");
Console.ReadKey();

await endpointInstance.Stop();
await endpointInstance.Stop();
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,17 @@

Console.Title = "EndpointPostgreSql";

#region PostgreSqlConfig

var endpointConfiguration = new EndpointConfiguration("EndpointPostgreSql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();


#region PostgreSqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var password = Environment.GetEnvironmentVariable("PostgreSqlPassword");

if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'PostgreSqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("PostgreSqlUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'PostgreSqlUserName' from Environment variables.");
}
var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();

var connection = $"Host=localhost;Username={username};Password={password};Database=NsbSamplesSqlPersistence";
var connection = "Host=localhost;Username=postgres;Password=yourStrong(!)Password;Database=NsbSamplesSqlPersistence";

var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();
persistence.ConnectionBuilder(() => new NpgsqlConnection(connection));
#endregion

dialect.JsonBParameterModifier(
modifier: parameter =>
Expand All @@ -37,17 +25,9 @@
npgsqlParameter.NpgsqlDbType = NpgsqlDbType.Jsonb;
});

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new NpgsqlConnection(connection);
});

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand All @@ -58,4 +38,4 @@
Console.WriteLine("Press any key to exit");
Console.ReadKey();

await endpointInstance.Stop();
await endpointInstance.Stop();
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = "Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

SqlHelper.EnsureDatabaseExists(connectionString);

endpointConfiguration.UseTransport(new LearningTransport());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,21 @@

Console.Title = "EndpointMySql";

#region MySqlConfig

var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region MySqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("MySqlPassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("MySqlUserName");
if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
}
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
persistence.SqlDialect<SqlDialect.MySql>();
persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new MySqlConnection(connection);
});
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

var connection = "server=localhost;user=root;database=sqlpersistencesample;port=3306;password=yourStrong(!)Password;AllowUserVariables=True;AutoEnlist=false";

persistence.ConnectionBuilder(() => new MySqlConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,21 @@

Console.Title = "EndpointOracle";

#region OracleConfig

var endpointConfiguration = new EndpointConfiguration("EndpointOracle");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region OracleConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("OraclePassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'OraclePassword' from Environment variables.");
}

var username = Environment.GetEnvironmentVariable("OracleUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'OracleUserName' from Environment variables.");
}

var connection = $"Data Source=localhost;User Id={username}; Password={password}; Enlist=false";

persistence.SqlDialect<SqlDialect.Oracle>();

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new OracleConnection(connection);
});
var connection = "Data Source=localhost;User Id=SYSTEM; Password=yourStrong(!)Password; Enlist=false";

persistence.ConnectionBuilder(() => new OracleConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,17 @@

Console.Title = "EndpointPostgreSql";

#region PostgreSqlConfig

var endpointConfiguration = new EndpointConfiguration("EndpointPostgreSql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();


#region PostgreSqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var password = Environment.GetEnvironmentVariable("PostgreSqlPassword");

if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'PostgreSqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("PostgreSqlUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'PostgreSqlUserName' from Environment variables.");
}
var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();

var connection = $"Host=localhost;Username={username};Password={password};Database=NsbSamplesSqlPersistence";
var connection = "Host=localhost;Username=postgres;Password=yourStrong(!)Password;Database=NsbSamplesSqlPersistence";

var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();
persistence.ConnectionBuilder(() => new NpgsqlConnection(connection));
#endregion

dialect.JsonBParameterModifier(
modifier: parameter =>
Expand All @@ -37,17 +25,9 @@
npgsqlParameter.NpgsqlDbType = NpgsqlDbType.Jsonb;
});

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new NpgsqlConnection(connection);
});

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

Console.Title = "EndpointSqlServer";

#region sqlServerConfig

var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointSqlServer");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region sqlServerConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = "Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

SqlHelper.EnsureDatabaseExists(connectionString);

endpointConfiguration.UseTransport(new LearningTransport());
Expand Down
Loading

0 comments on commit f9e807b

Please sign in to comment.