Skip to content

Commit 8b84fa2

Browse files
Feature: Provision Collections Directly (#11)
* feature: create collections direct mongodb://localhost:27017 * fix: oops * style: run cleaner
1 parent 5c05707 commit 8b84fa2

File tree

2 files changed

+70
-33
lines changed

2 files changed

+70
-33
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using EntityDb.MongoDb.Extensions;
2+
using MongoDB.Driver;
3+
using System.CommandLine;
4+
using System.CommandLine.Invocation;
5+
using System.Threading.Tasks;
6+
7+
namespace EntityDb.MongoDb.Provisioner.Commands
8+
{
9+
public class CreateCollectionsDirect : CommandBase
10+
{
11+
public static void AddTo(RootCommand rootCommand)
12+
{
13+
var createCollectionsDirect = new Command("create-collections-direct");
14+
15+
AddEntityNameArgumentTo(createCollectionsDirect);
16+
17+
var connectionStringArgument = new Argument<string>("connection-string", "The connection string to the mongodb instance.");
18+
19+
createCollectionsDirect.AddArgument(connectionStringArgument);
20+
21+
createCollectionsDirect.Handler = CommandHandler.Create(async (string entityName, string connectionString) =>
22+
{
23+
await Execute(entityName, connectionString);
24+
});
25+
26+
rootCommand.AddCommand(createCollectionsDirect);
27+
}
28+
29+
public static async Task Execute(string entityName, string connectionString)
30+
{
31+
var mongoClient = new MongoClient(connectionString);
32+
33+
await mongoClient.ProvisionCollections(entityName);
34+
}
35+
}
36+
}
Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
using EntityDb.MongoDb.Provisioner.Commands;
2-
using System;
3-
using System.CommandLine;
4-
using System.CommandLine.Parsing;
5-
using System.Threading.Tasks;
6-
7-
namespace EntityDb.MongoDb.Provisioner
8-
{
9-
public class Program
10-
{
11-
public static Task<int> Main(string[] args)
12-
{
13-
#if DEBUG
14-
if (args.Length == 0)
15-
{
16-
Console.Write("Please enter args: ");
17-
18-
var input = Console.ReadLine() ?? string.Empty;
19-
20-
args = input.Split(' ');
21-
}
22-
#endif
23-
24-
var rootCommand = new RootCommand();
25-
26-
CreateRole.AddTo(rootCommand);
27-
CreateUser.AddTo(rootCommand);
28-
CreateCollections.AddTo(rootCommand);
29-
30-
return rootCommand.InvokeAsync(args);
31-
}
32-
}
33-
}
1+
using EntityDb.MongoDb.Provisioner.Commands;
2+
using System;
3+
using System.CommandLine;
4+
using System.CommandLine.Parsing;
5+
using System.Threading.Tasks;
6+
7+
namespace EntityDb.MongoDb.Provisioner
8+
{
9+
public class Program
10+
{
11+
public static Task<int> Main(string[] args)
12+
{
13+
#if DEBUG
14+
if (args.Length == 0)
15+
{
16+
Console.Write("Please enter args: ");
17+
18+
var input = Console.ReadLine() ?? string.Empty;
19+
20+
args = input.Split(' ');
21+
}
22+
#endif
23+
24+
var rootCommand = new RootCommand();
25+
26+
CreateRole.AddTo(rootCommand);
27+
CreateUser.AddTo(rootCommand);
28+
CreateCollections.AddTo(rootCommand);
29+
CreateCollectionsDirect.AddTo(rootCommand);
30+
31+
return rootCommand.InvokeAsync(args);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)