Adding entity linking

This commit is contained in:
2024-04-23 08:56:01 +02:00
parent 3a46e20d38
commit abd116b032
17 changed files with 236 additions and 94 deletions

View File

@@ -14,20 +14,4 @@ public partial class MycroForge
AddCommand((subCommandOf as Command)!);
}
}
public class Run : Command, ISubCommandOf<MycroForge>
{
public Run() : base("run", "Run your app")
{
this.SetHandler(ExecuteAsync);
}
private async Task ExecuteAsync()
{
await Bash.ExecuteAsync([
"source .venv/bin/activate",
"uvicorn main:app --reload"
]);
}
}
}

View File

@@ -0,0 +1,37 @@
using System.CommandLine;
using MycroForge.CLI.Commands.Interfaces;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Entity
{
public partial class Link
{
public class Many : Command, ISubCommandOf<Link>
{
private static readonly Argument<string> NameArgument =
new(name: "primary", description: "The left side of the relation");
private static readonly Option<string> ToOneOption =
new(name: "--to-one", description: "The right side of the relation");
private static readonly Option<string> ToManyOption =
new(name: "--to-many", description: "The right side of the relation");
public Many() : base("many", "Define a n:m relation")
{
AddArgument(NameArgument);
AddOption(ToOneOption);
AddOption(ToManyOption);
this.SetHandler(ExecuteAsync);
}
private async Task ExecuteAsync()
{
}
}
}
}
}

View File

@@ -0,0 +1,38 @@
using System.CommandLine;
using MycroForge.CLI.Commands.Interfaces;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Entity
{
public partial class Link
{
public class One : Command, ISubCommandOf<Link>
{
private static readonly Argument<string> NameArgument =
new(name: "primary", description: "The left side of the relation");
private static readonly Option<string> ToOneOption =
new(name: "--to-one", description: "The right side of the relation");
private static readonly Option<string> ToManyOption =
new(name: "--to-many", description: "The right side of the relation");
public One() : base("one", "Define a 1:n relation")
{
AddArgument(NameArgument);
AddOption(ToOneOption);
AddOption(ToManyOption);
this.SetHandler(ExecuteAsync);
}
private async Task ExecuteAsync()
{
}
}
}
}
}

View File

@@ -0,0 +1,20 @@
using System.CommandLine;
using MycroForge.CLI.Commands.Interfaces;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Entity
{
public partial class Link : Command, ISubCommandOf<Entity>
{
public Link(IEnumerable<ISubCommandOf<Link>> commands) :
base("link", "Define relationships between entities")
{
foreach (var command in commands)
AddCommand((command as Command)!);
}
}
}
}

View File

@@ -0,0 +1,17 @@
using System.CommandLine;
using MycroForge.CLI.Commands.Interfaces;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Entity : Command, ISubCommandOf<MycroForge>
{
public Entity(IEnumerable<ISubCommandOf<Entity>> commands) :
base("entity", "Manage the entities in your project")
{
foreach (var command in commands.Cast<Command>())
AddCommand(command);
}
}
}

View File

@@ -9,19 +9,22 @@ public partial class MycroForge
{
public partial class Generate
{
// ReSharper disable once MemberHidesStaticFromOuterClass
public class Entity : Command, ISubCommandOf<Generate>
{
private static readonly string[] Template =
[
"from sqlalchemy import INTEGER, Column, String",
"from sqlalchemy import String",
"from sqlalchemy.orm import Mapped, mapped_column",
"from orm.entities.entity_base import EntityBase",
"",
"class %class_name%(EntityBase):",
"\t__tablename__ = \"%table_name%\"",
"\tid = Column(INTEGER, primary_key=True)",
"\tid: Mapped[int] = mapped_column(primary_key=True)",
"\tvalue: Mapped[str] = mapped_column(String(255))",
"",
"\tdef __repr__(self) -> str:",
"\t\treturn f\"%class_name%(id={self.id!r})\""
"\t\treturn f\"%class_name%(id={self.id!r}, value={self.value!r})\""
];
private static readonly Argument<string> NameArgument =

View File

@@ -1,24 +0,0 @@
using System.CommandLine;
using MycroForge.CLI.Commands.Interfaces;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public class Rewrite : Command, ISubCommandOf<MycroForge>
{
public Rewrite() : base("rewrite", "Test a python source rewriter.")
{
this.SetHandler(ExecuteAsync);
}
private async Task ExecuteAsync()
{
// var path = Path.Combine(Directory.GetCurrentDirectory(), "main.py");
// var source = await File.ReadAllTextAsync(path);
// var rewriter = new TestRewriter(source);
// var rewrite = rewriter.Rewrite();
// await File.WriteAllTextAsync(path, rewrite);
}
}
}

View File

@@ -0,0 +1,23 @@
using System.CommandLine;
using MycroForge.CLI.Commands.Interfaces;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public class Run : Command, ISubCommandOf<MycroForge>
{
public Run() : base("run", "Run your app")
{
this.SetHandler(ExecuteAsync);
}
private async Task ExecuteAsync()
{
await Bash.ExecuteAsync([
"source .venv/bin/activate",
"uvicorn main:app --reload"
]);
}
}
}