From e2d8804a30b5601e3cd9bfdbd848ad02b8f86475 Mon Sep 17 00:00:00 2001 From: luozq Date: Thu, 18 Jul 2024 09:55:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=BE=8B=EF=BC=88=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=A4=9A=E4=B8=AA=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/guide/getting-started.md | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1a23ca75a8..cd86c9bdde 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## install ```bash -npm install -g pnpm@next-7 +npm install -g pnpm ``` ```bash diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index 84cbbe2726..e30d01bc9a 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -103,7 +103,7 @@ using(IServiceScope serviceScope = app.Services.CreateScope()) ::: - [.NET Core 注入多个 FreeSql 实例](../extra/idlebus-freesql.md) -- .NET Framework 单例 +- .NET Framework 单例(支持连接多个数据库) ```csharp public class DB @@ -114,6 +114,18 @@ public class DB .UseAutoSyncStructure(true) //自动同步实体结构到数据库,FreeSql不会扫描程序集,只有CRUD时才会生成表。 .Build()); public static IFreeSql Sqlite => sqliteLazy.Value; + + static Lazy mysqlLazy = new Lazy(() => new FreeSqlBuilder() + .UseConnectionString(FreeSql.DataType.MySql, @"Data Source=localhost;Port=3306;User ID=root;Password=root;Initial Catalog=DispatchProxy;Charset=utf8mb4;SslMode=none;Max pool size=50;Connection LifeTime=20") + .UseAutoSyncStructure(true) //自动同步实体结构到数据库,FreeSql不会扫描程序集,只有CRUD时才会生成表。 + //.UseAdoConnectionPool(true) //使用Ado原生连接池, + .UseNameConvert(NameConvertType.PascalCaseToUnderscoreWithLower) //数据库、表、字段使用下划线命名,代码使用C#大驼峰 + .UseMonitorCommand( //监听SQL命令 + cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) + ) + .Build()); + + public static IFreeSql MySql => mysqlLazy.Value; } ``` @@ -210,7 +222,7 @@ fsql.Delete() | DataType | ConnectionString | | ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| DataType.MySql | Data Source=127.0.0.1;Port=3306;User ID=root;Password=root; Initial Catalog=cccddd;Charset=utf8; SslMode=none;Min pool size=1 | +| DataType.MySql | Data Source=127.0.0.1;Port=3306;User ID=root;Password=root; Initial Catalog=cccddd;Charset=utf8mb4; SslMode=none;Min pool size=1 | | DataType.PostgreSQL | Host=192.168.164.10;Port=5432;Username=postgres;Password=123456; Database=tedb;ArrayNullabilityMode=Always;Pooling=true;Minimum Pool Size=1 | | DataType.SqlServer | Data Source=.;User Id=sa;Password=123456;Initial Catalog=freesqlTest;Encrypt=True;TrustServerCertificate=True;Pooling=true;Min Pool Size=1 | | DataType.Oracle | user id=user1;password=123456; data source=//127.0.0.1:1521/XE;Pooling=true;Min Pool Size=1 |