当前位置: 首页 > news >正文

郑州微信网站如何在手机使用wordpress

郑州微信网站,如何在手机使用wordpress,学习做网站建设的学校,衡阳网站建设mdawl本文主要是使用异步方式#xff0c;体验 litedb 基本的 crud 操作。 LiteDB 是一款轻量级、快速且免费的 .NET NoSQL 嵌入式数据库#xff0c;专为小型本地应用程序设计。它以单一数据文件的形式提供服务#xff0c;支持文档存储和查询功能#xff0c;适用于桌面应用、移动… 本文主要是使用异步方式体验 litedb 基本的 crud 操作。 LiteDB 是一款轻量级、快速且免费的 .NET NoSQL 嵌入式数据库专为小型本地应用程序设计。它以单一数据文件的形式提供服务支持文档存储和查询功能适用于桌面应用、移动应用和小型 Web 应用等场景。 LiteDB 的主要特点包括 无服务器的 NoSQL 文档存储LiteDB 是一个嵌入式数据库无需独立服务器数据存储在一个单一文件中类似于 SQLite。简单易用的 APILiteDB 提供类似 MongoDB 的简单 API支持 LINQ 查询和 SQL-like 命令使得开发者可以轻松上手。线程安全和 ACID 事务支持LiteDB 支持线程安全操作和完整的 ACID 事务处理确保数据的一致性和完整性。数据恢复功能LiteDB 使用写前日志WAL机制来保证数据恢复能力即使在写入失败的情况下也能恢复数据。跨平台支持LiteDB 可以在 Windows、Linux 和 macOS 等多个平台上运行具有良好的跨平台兼容性。加密存储LiteDB 支持使用 DES 或 AES 加密算法对数据文件进行加密保障数据的安全性。文件和流数据存储LiteDB 支持存储文件和流数据类似于 MongoDB 的 GridFS 功能。开源免费LiteDB 是一个开源MIT项目任何人都可以使用和修改其代码并且完全免费包括商业用途。 LiteDB 的使用非常简单可以通过 NuGet 包管理器轻松安装并且提供了丰富的文档和示例代码帮助开发者快速上手。此外LiteDB 还提供了一个名为 LiteDB Studio 的图形用户界面工具方便用户管理和可视化数据库内容。 总之LiteDB 是一款功能强大、易于使用的 NoSQL 数据库解决方案适用于多种场景值得开发者关注和尝试。 使用 .NET CLI 创建一个控制台应用程序可以按照以下步骤进行 安装 .NET 9 SDK首先确保你已经安装了 .NET 9 SDK。你可以从官方网站下载并安装最新版本的 .NET SDK。 创建新的控制台应用程序使用 dotnet new console 命令创建一个新的控制台应用程序。这个命令会生成一个包含基本结构的项目文件夹。 dotnet new console -n LiteDBExample导航到项目目录进入刚刚创建的项目目录。 cd LiteDBExample运行应用程序使用 dotnet run 命令运行应用程序。 dotnet run基础控制台项目就创建好了丝滑般体验 接下来我们使用 litedb 提供的 nuget 包进行简单的封装构建出异步操作的 crud 方法 。 安装相关 nuget 包 Project SdkMicrosoft.NET.SdkPropertyGroupOutputTypeExe/OutputTypeTargetFrameworknet9.0/TargetFrameworkImplicitUsingsenable/ImplicitUsingsNullableenable/Nullable/PropertyGroupItemGroupPackageReference IncludeLiteDB Version5.0.21 /PackageReference IncludeLiteDB.Async Version0.1.8 /PackageReference IncludeMicrosoft.Extensions.DependencyInjection Version9.0.0 //ItemGroup/Project创建实体类型 Person public class Person {public Guid Id { get; set; } Guid.NewGuid();public string Name { get; set; } default!;public uint Age { get; set; } }定义仓储类规范IRepository using LiteDB;namespace LiteDBExample.Core.Interfaces;public interface IRepositoryTEntity where TEntity : class {TaskBsonValue AddAsync(TEntity entity);Taskint AddRangeAsync(IEnumerableTEntity entities);TaskIEnumerableTEntity GetAllAsync();TaskTEntity? GetByIdAsync(object id);Taskbool UpdateAsync(TEntity entity);Taskint UpdateRangeAsync(IEnumerableTEntity entities);Taskbool DeleteAsync(object id);Taskint DeleteRangeAsync(IEnumerableobject ids); }实现 PersonDbContext using LiteDB; using LiteDB.Async; using LiteDBExample.Core.Entities;namespace LiteDBExample.Data;public class PersonDbContext(string connectionString) : IDisposable {private readonly LiteDatabaseAsync _database new(connectionString);public TaskBsonValue AddAsync(Person person){var collection _database.GetCollectionPerson(people);return collection.InsertAsync(person);}public Taskint AddRangeAsync(IEnumerablePerson persons){var collection _database.GetCollectionPerson(people);return collection.InsertAsync(persons);}public TaskIEnumerablePerson GetAllAsync(){var collection _database.GetCollectionPerson(people);return collection.FindAllAsync();}public TaskPerson? GetByIdAsync(object id){BsonValue bsonId new(id);var collection _database.GetCollectionPerson(people);return collection.FindByIdAsync(bsonId);}public Taskbool UpdateAsync(Person person){var collection _database.GetCollectionPerson(people);return collection.UpdateAsync(person);}public Taskint UpdateRangeAsync(IEnumerablePerson persons){var collection _database.GetCollectionPerson(people);return collection.UpdateAsync(persons);}public Taskbool DeleteAsync(object id){BsonValue bsonId new(id);var collection _database.GetCollectionPerson(people);return collection.DeleteAsync(bsonId);}public Taskint DeleteRangeAsync(IEnumerableobject ids){var collection _database.GetCollectionPerson(people);return collection.DeleteManyAsync(a ids.Contains(a.Id));}public void Dispose(){_database.Dispose();} }定义 Person 类仓储IPersonRepository using LiteDBExample.Core.Entities; using LiteDBExample.Core.Interfaces;namespace LiteDBExample.Repositories;public interface IPersonRepository : IRepositoryPerson { }实现 Person 类仓储PersonRepository using LiteDB; using LiteDBExample.Core.Entities; using LiteDBExample.Data;namespace LiteDBExample.Repositories;public class PersonRepository(PersonDbContext context) : IPersonRepository {private readonly PersonDbContext _context context ?? throw new ArgumentNullException(nameof(context));public TaskBsonValue AddAsync(Person entity){return _context.AddAsync(entity);}public Taskint AddRangeAsync(IEnumerablePerson entities){return _context.AddRangeAsync(entities);}public TaskIEnumerablePerson GetAllAsync(){return _context.GetAllAsync();}public TaskPerson? GetByIdAsync(object id){return _context.GetByIdAsync(id);}public Taskbool UpdateAsync(Person entity){return _context.UpdateAsync(entity);}public Taskint UpdateRangeAsync(IEnumerablePerson entities){return _context.UpdateRangeAsync(entities);}public Taskbool DeleteAsync(object id){return _context.DeleteAsync(id);}public Taskint DeleteRangeAsync(IEnumerableobject ids){return _context.DeleteRangeAsync(ids);} }在 Program.cs 中应用 IPersonRepository using LiteDBExample.Core.Entities; using LiteDBExample.Repositories; using Microsoft.Extensions.DependencyInjection; using LiteDBExample.Data;namespace LiteDBExample;internal class Program {static async Task Main(string[] args){Console.WriteLine(Hello, LiteDB!);var services new ServiceCollection();ConfigureServices(services);using var serviceProvider services.BuildServiceProvider();var personRepository serviceProvider.GetRequiredServiceIPersonRepository();// 多个 Personvar newPeople new ListPerson{new Person { Name John Kiny, Age 16 },new Person { Name John Doe, Age 30 },new Person { Name Jane Smith, Age 28 },new Person { Name Alice Johnson, Age 35 }};try{Console.WriteLine( litedb Async Method Test);{// 添加单个 Personvar person new Person { Name Alice Array, Age 32 };var bsonId await personRepository.AddAsync(person);Console.WriteLine($bsonId{bsonId});// 查询单个 Personvar queryPerson await personRepository.GetByIdAsync(bsonId);Console.WriteLine($guid{queryPerson.Id}, {queryPerson.Name} is {queryPerson.Age} years old.);// 更新单个 Personperson.Age 1;person.Name Array;var updateCount await personRepository.UpdateAsync(person);Console.WriteLine($updateCount{updateCount});// 删除单个 Personvar deleteCount await personRepository.DeleteAsync(bsonId);Console.WriteLine($deleteCount{deleteCount});// 批量添加多个 Personint addRange await personRepository.AddRangeAsync(newPeople);Console.WriteLine($addRange{addRange});// 查询所有 Personvar people await personRepository.GetAllAsync();foreach (var p in people){Console.WriteLine($guid{p.Id}, {p.Name} is {p.Age} years old.);}// 批量更新多个 Personvar updatedPeople people.Select(p new Person { Id p.Id, Name p.Name, Age p.Age 1 });int updateRows await personRepository.UpdateRangeAsync(updatedPeople);Console.WriteLine($updateRows{updateRows});// 批量删除多个 Personvar idsToDelete new Listobject();foreach (var item in people.Select(p p.Id)){idsToDelete.Add(item);};var ids idsToDelete.AsEnumerable();int deleteRows await personRepository.DeleteRangeAsync(ids);Console.WriteLine($deleteRows{deleteRows});}Console.ReadLine();}catch (Exception ex){Console.WriteLine($An error occurred: {ex.Message});}}private static void ConfigureServices(IServiceCollection services){services.AddScopedIPersonRepository, PersonRepository();services.AddScopedPersonDbContext(provider new PersonDbContext(filenamelitedb_example.db));} }运行应用dotnet run 使用 LiteDB.Studio 工具查看 litedb 数据 当批量添加数据的时候查看数据信息如下 Grid 查看 Text 查看 从上图中可以看到 litedb_example.db 文件非常轻量大概 30kb 左右
http://www.w-s-a.com/news/657653/

相关文章:

  • 做物品租赁网站清新wordpress主题
  • 优秀专题网站家居企业网站建设市场
  • 中山市有什么网站推广wordpress轻应用主机
  • 洗头竖鞋带名片改良授权做网站不贵整个世界
  • 设计电子商务网站建设方案微信如何开发自己的小程序
  • 建设网站公司哪里好相关的热搜问题解决方案做网站要看什么书
  • 网站建设重要性黄岐建网站
  • 做网站电销《电子商务网站建设》精品课
  • 地方商城网站海外网站推广方法
  • 乐山 网站建设安阳给商家做网站推广
  • 网站空间一般多大邢台网站建设有哪些
  • h5网站开发工具有哪些wordpress清空post表
  • 公司开网站干嘛怎么制作一个免费的网站模板
  • 群晖wordpress搭建网站网站建设及管理
  • 中山企业网站建设公司抖音代运营合作模式
  • 南通营销网站开发做网站页面多少钱
  • 桂林生活网官方网站云主机和云电脑的区别
  • 内部网络网站怎么做vue做单页面网站
  • 如何建立网站教程wordpress粘帖图片
  • 广东网站备案要多久网站开发 pdf 文字版
  • 学校网站方案帮别人做钓鱼网站吗
  • 如何加强网站建设和信息宣传wordpress 搜索提示
  • 灰色网站怎么做php yaf 网站开发框架
  • 浙江建设网站首页提供做网站公司有哪些
  • 建公司网站报价公司seo是什么级别
  • 可信赖的武进网站建设中山网站建设方案
  • 网站设计方面有什么公司运动鞋网站建设目的
  • 学校门户网站流程建设方案找人做网站 多少钱
  • 网站域名更换相应内容网站策划 要求
  • 百盛联合建设集团网站开发网站的步骤