Skip to content

Commit

Permalink
Add support for database config in project metadata (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs authored Jul 13, 2023
1 parent fa524cb commit d6dc6b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit d6dc6b0

Please # to comment.