Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for database config in project metadata #60

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/EdgeDB.Net.Driver/EdgeDBConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,12 @@ public static EdgeDBConnection FromProjectFile(string path)
if (!ConfigUtils.TryResolveInstanceCloudProfile(projectDir, out string? profile, out string? inst) || inst is null)
throw new FileNotFoundException($"Could not find instance name under project directory {projectDir}");

return FromInstanceName(inst, profile);
var connection = FromInstanceName(inst, profile);

if (ConfigUtils.TryResolveProjectDatabase(projectDir, out var database))
connection.Database = database;

return connection;
}

/// <summary>
Expand Down
20 changes: 19 additions & 1 deletion src/EdgeDB.Net.Driver/Utils/ConfigUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,25 @@ public static bool TryResolveInstanceTOML(string cdir, [NotNullWhen(true)] out s
return false;
}

public static bool TryResolveInstanceCLoudProfile(out string? profile, out string? linkedInstanceName)
public static bool TryResolveProjectDatabase(string stashDir, [NotNullWhen(true)] out string? database)
{
database = null;

if (!Directory.Exists(stashDir))
return false;

var databasePath = Path.Combine(stashDir, "database");

if (File.Exists(databasePath))
{
database = File.ReadAllText(databasePath);
return true;
}

return false;
}

public static bool TryResolveInstanceCloudProfile(out string? profile, out string? linkedInstanceName)
{
profile = null;
linkedInstanceName = null;
Expand Down