Use a local SQLite3 backend instead of PostgreSQL Docker container.
* The provided SQLite3 database contains the required schemas, but no data and can be reset to if required. * Remove all references to PostgreSQL in documentation and configuration. * Replace native sqlite3 command with a console app to remove dependency on SQLite3 installation.
This commit is contained in:
24
show-posts/Post.cs
Normal file
24
show-posts/Post.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
[Table("posts")]
|
||||
public class Post
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("user_id")]
|
||||
public int UserId { get; set; }
|
||||
|
||||
[Column("title")]
|
||||
[Required]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
[Column("body")]
|
||||
[Required]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
[Column("updated_at")]
|
||||
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.Parse("1970-01-01T00:00:00Z"); // TODO: Remove the default value in Phase 3.
|
||||
}
|
||||
20
show-posts/PostsDbContext.cs
Normal file
20
show-posts/PostsDbContext.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public class PostsDbContext : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
var currentDir = System.IO.Directory.GetCurrentDirectory();
|
||||
int showPostsIndex = currentDir.IndexOf("show-posts");
|
||||
if (showPostsIndex > -1)
|
||||
{
|
||||
// Running from the bin directory, get the parent of "show-posts".
|
||||
currentDir = currentDir.Substring(0, showPostsIndex - 1);
|
||||
}
|
||||
string repoRoot = currentDir;
|
||||
|
||||
optionsBuilder.UseSqlite($"Data Source={repoRoot}/service/service.db;Mode=ReadOnly;");
|
||||
}
|
||||
|
||||
public DbSet<Post> Posts { get; set; }
|
||||
}
|
||||
4
show-posts/Program.cs
Normal file
4
show-posts/Program.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
using table.lib;
|
||||
|
||||
using var context = new PostsDbContext();
|
||||
Table<Post>.Add(context.Posts.ToList()).ToConsole();
|
||||
17
show-posts/show-posts.csproj
Normal file
17
show-posts/show-posts.csproj
Normal file
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>show_posts</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.13" />
|
||||
<PackageReference Include="table.lib" Version="1.17.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user