Skip to content

Commit d2c9014

Browse files
flatrick-privdroyad
authored andcommitted
improve clarity of which methods are being used
By putting each type into their own method, the reader can more quickly discern which information is relevant to them. By explicitly stating which method's being used, we remove the mental load from the reader of figuring out which namespace a function belongs to and thereby making it clearer to the user what is being used. (cherry picked from commit 193c9a02ef988585e72c82f65358864bc22cf701)
1 parent c787c20 commit d2c9014

File tree

1 file changed

+59
-31
lines changed

1 file changed

+59
-31
lines changed

src/Sample/Program.cs

+59-31
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,91 @@
11
using System;
2-
using System.Diagnostics;
3-
using System.Reflection;
4-
using DbUp;
5-
using DbUp.Engine;
6-
using DbUp.SQLite.Helpers;
72

83
namespace SQLiteSampleApplication
94
{
10-
class Program
5+
public static class Program
116
{
127
static void Main()
138
{
14-
using (var database = new TemporarySQLiteDatabase("test"))
15-
{
16-
database.Create();
9+
InMemoryDb();
10+
TemporaryFileDb();
11+
PermanentFileDb();
12+
}
1713

14+
static void InMemoryDb()
15+
{
16+
using (var database = new DbUp.SQLite.Helpers.InMemorySQLiteDatabase())
17+
{
1818
var upgrader =
19-
DeployChanges.To
20-
.SQLiteDatabase(database.SharedConnection)
21-
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
22-
.LogToConsole()
23-
.Build();
19+
DbUp.DeployChanges.To
20+
.SQLiteDatabase(database.ConnectionString)
21+
.WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly())
22+
.LogToConsole()
23+
.Build();
24+
25+
var watch = new System.Diagnostics.Stopwatch();
2426

25-
var watch = new Stopwatch();
2627
watch.Start();
28+
DbUp.Engine.DatabaseUpgradeResult result = upgrader.PerformUpgrade();
29+
watch.Stop();
2730

28-
var result = upgrader.PerformUpgrade();
31+
Display("InMemory", result, watch.Elapsed);
32+
} // Database will be deleted at this point
33+
}
2934

35+
static void TemporaryFileDb()
36+
{
37+
using (var database = new DbUp.SQLite.Helpers.TemporarySQLiteDatabase("test.db"))
38+
{
39+
var upgrader =
40+
DbUp.DeployChanges.To
41+
.SQLiteDatabase(database.SharedConnection)
42+
.WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly())
43+
.LogToConsole()
44+
.Build();
45+
46+
var watch = new System.Diagnostics.Stopwatch();
47+
48+
watch.Start();
49+
DbUp.Engine.DatabaseUpgradeResult result = upgrader.PerformUpgrade();
3050
watch.Stop();
31-
Display("File", result, watch.Elapsed);
51+
52+
Display("Temporary file", result, watch.Elapsed);
3253
} // Database will be deleted at this point
54+
}
55+
56+
static void PermanentFileDb()
57+
{
58+
Microsoft.Data.Sqlite.SqliteConnection connection = new("Data Source=dbup.db");
3359

34-
using (var database = new InMemorySQLiteDatabase())
60+
using (var database = new DbUp.SQLite.Helpers.SharedConnection(connection))
3561
{
36-
var upgrader =
37-
DeployChanges.To
38-
.SQLiteDatabase(database.ConnectionString)
39-
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
62+
var upgrader = DbUp.DeployChanges
63+
.To
64+
.SQLiteDatabase(connection.ConnectionString)
65+
.WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly())
4066
.LogToConsole()
4167
.Build();
4268

43-
var watch = new Stopwatch();
44-
watch.Start();
45-
46-
var result = upgrader.PerformUpgrade();
69+
var watch = new System.Diagnostics.Stopwatch();
4770

71+
watch.Start();
72+
DbUp.Engine.DatabaseUpgradeResult result = upgrader.PerformUpgrade();
4873
watch.Stop();
49-
Display("InMemory", result, watch.Elapsed);
50-
} // Database will disappear from memory at this point
74+
75+
Display("Permanent file", result, watch.Elapsed);
76+
} // Database will NOT be deleted at this point
5177
}
5278

53-
static void Display(string dbType, DatabaseUpgradeResult result, TimeSpan ts)
79+
static void Display(string dbType, DbUp.Engine.DatabaseUpgradeResult result, TimeSpan ts)
5480
{
5581
// Display the result
5682
if (result.Successful)
5783
{
5884
Console.ForegroundColor = ConsoleColor.Green;
5985
Console.WriteLine("Success!");
60-
Console.WriteLine("{0} Database Upgrade Runtime: {1}", dbType,
86+
Console.WriteLine(
87+
"{0} Database Upgrade Runtime: {1}",
88+
dbType,
6189
string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10));
6290
Console.ReadKey();
6391
}
@@ -70,4 +98,4 @@ static void Display(string dbType, DatabaseUpgradeResult result, TimeSpan ts)
7098
}
7199
}
72100
}
73-
}
101+
}

0 commit comments

Comments
 (0)