Wednesday, November 13, 2024

docker host name/address

if don't wanna use the ip address

docker get IP address command:

docker inspect -f '{{range. NetworkSettings. Networks}}{{. IPAddress}}{{end}}' container_name_or_id

use host.docker.internal

 


Monday, November 11, 2024

.Net Core connect to postgresql

 1. appsettings.json

  "ConnectionStrings": {
    "DefaultConnection": ""
  }

2. Program.cs
builder.Services.AddDbContext<ApiDbCopntext>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

3. Models/ folder
add Table Class
namespace ReactAPIApp.Server.Models
{
    public class Driver
    {
        public int Id { get; set; }
        public string Name { get; set; } = null!;
        public int DriverNumber { get; set; }
    }
}

4. Add Context for example add Data folder

Data/ApiDbContext.cs

using Microsoft.EntityFrameworkCore;

using ReactAPIApp.Server.Models;

namespace ReactAPIApp.Server.Data
{
    public class ApiDbContext : DbContext
    {
        public ApiDbContext(DbContextOptions<ApiDbContext> options) : base(options){}
        public DbSet<Driver> Drivers { get; set; }
    }
}

5. run migrate command
if from package manager console
PM> Add-Migration initial

if from package manager console

Friday, November 8, 2024

js function 严格模式 use strict

 禁止function 内部的this指向winodows

class 中的function,都已默认开启了严格模式