LiteDB NoSQL 文档存储 sql语句

1.LiteDB 一个小巧、快速、轻量级的 NoSQL 嵌入式数据库

2。100% C# 代码,支持 .NET 3.5 / .NET 4.0 / NETStandard 1.3 / NETStandard 2.0,单 DLL (小于 300 kb)

下载数据库文件

下载数据库管理工具

支持sql语句

# get the first 5 documents from the movies collection
Find-LiteDBDocument movies -Sql "Select $ from movies limit 5"

# get the first 5 documents with selected properties or fields from the movies collection
Find-LiteDBDocument movies -Sql "Select _id,Title from movies limit 5"

# using where to filter the results - string filter
Find-LiteDBDocument movies -Sql "Select _id,Title from movies Where MPAA = 'PG-13'"

# using where to filter the results - greaterthan
Find-LiteDBDocument movies -Sql "Select _id,Title from movies Where Rating > 7.5"

# using multiple where filters. ( movies that contain 'talking' in their title)
Find-LiteDBDocument movies -Sql "Select _id,Title from movies where MPAA = 'PG-13' and Title like '%talking'"

# Sorting by name descending
Find-LiteDBDocument movies -Sql "Select _id,Title from movies where MPAA = 'PG-13' order by Title desc"

# date filter
Find-LiteDBDocument movies -Sql "select _id,Title,ReleaseDate from test where ReleaseDate > datetime('8/16/1989') order by Releasedate desc"

# using Functions
# get the first 5 documents with selected properties or fields from the movies collection
Find-LiteDBDocument movies -Sql "Select upper(Title),_id,MPAA from movies limit 5"

 

C# 使用

// 创建你的 POCO 类
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public string[] Phones { get; set; }
    public bool IsActive { get; set; }
}

// 打开数据库 (如果不存在则创建)
using(var db = new LiteDatabase(@"MyData.db"))
{
    // 获得 customer 集合
    var col = db.GetCollection<Customer>("customers");

    // 创建你的新 customer 实例
      var customer = new Customer
    { 
        Name = "John Doe", 
        Phones = new string[] { "8000-0000", "9000-0000" }, 
        Age = 39,
        IsActive = true
    };

    // 在 Name 字段上创建唯一索引
    col.EnsureIndex(x => x.Name, true);

    // 插入新的 customer 文档 (Id 是自增的)
    col.Insert(customer);

    // 更新集合中的一个文档
    customer.Name = "Joana Doe";

    col.Update(customer);

    // 使用 LINQ 查询文档 (未使用索引)
    var results = col.Find(x => x.Age > 20);
}
 using(var db = new LiteDatabase(@"MyData.db"))
{
                    var gsi = gs.Query<ISSGateSentryInfo>().FirstOrDefault();
                    gsi.DutyID = result.Data.DUTYID;
                    gsi.DutyName = result.Data.USER_NAME;
                    gsi.DutyCode = result.Data.USER_CODE;
                    gsi.DutyTime = DateTime.Now;

                    gs.Update<ISSGateSentryInfo>(gsi);
                });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值