{"id":16239130,"url":"https://github.com/dominaezzz/sqlite-helper","last_synced_at":"2025-03-19T16:31:21.581Z","repository":{"id":90183792,"uuid":"97759227","full_name":"Dominaezzz/sqlite-helper","owner":"Dominaezzz","description":"Simple SQLite ORM for .NET applications.","archived":false,"fork":false,"pushed_at":"2019-12-06T00:15:37.000Z","size":504,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T09:05:04.064Z","etag":null,"topics":["database","linq","sqlite-orm"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dominaezzz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-19T20:40:28.000Z","updated_at":"2021-05-26T10:00:38.000Z","dependencies_parsed_at":"2023-06-03T02:00:26.641Z","dependency_job_id":null,"html_url":"https://github.com/Dominaezzz/sqlite-helper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dominaezzz%2Fsqlite-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dominaezzz%2Fsqlite-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dominaezzz%2Fsqlite-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dominaezzz%2Fsqlite-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dominaezzz","download_url":"https://codeload.github.com/Dominaezzz/sqlite-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244463745,"owners_count":20456941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","linq","sqlite-orm"],"created_at":"2024-10-10T13:42:25.016Z","updated_at":"2025-03-19T16:31:21.563Z","avatar_url":"https://github.com/Dominaezzz.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLite-helper\n\n[![](https://github.com/Dominaezzz/sqlite-helper/workflows/Build/badge.svg)](https://github.com/Dominaezzz/sqlite-helper/actions)\n\nAn SQLite ORM and client for .NET applications.\n\nSQLite-helper is an open source library built using .NETStandard to be cross-platform.\n\nThe main goal of the library was to support complex LINQ queries.\n\nInstall [SQLite Helper](https://www.nuget.org/packages/sqlite-helper/) from Nuget.\n\n# Examples\nClasses can be defined to access tables or views in the database.\nOptionally they can be decorated with attributes to allow the library make smarter when working with the database.\nYou don't need to define classes to access data but it makes it a whole lot easier.\n\n```csharp\n[Table(\"Products\")]\npublic class Product\n{\n    [PrimaryKey]\n    public int Id { get; set; }\n    public string Name { get; set; }\n    public decimal Price { get; set; }\n}\n\n[Table(\"Purchases\")]\npublic class Purchase\n{\n    [PrimaryKey]\n    public int Id { get; set}\n    public string Customer { get; set; }\n    public DateTime Date { get; set; }\n    [ForeignKey(\"Products\", \"Id\")]\n    public int ProductId { get; set; }\n}\n\npublic class ProductView\n{\n    public int Id { get; set; }\n    public string Name { get; set; }\n    public decimal Price { get; set; }\n    public int PurchaseCount { get; set; }\n}\n```\n\nTo use the models you extend the SQLiteDatabase class.\nIf you wish to create tables and/or views there are methods to help.\nYou can even create views from LINQ queries!\n\n```csharp\npublic class SQLiteDb : SQLiteDatabase\n{\n    public Table\u003cProduct\u003e Products { get; set; }\n    public Table\u003cPurchase\u003e Purchases { get; set; }\n    public View\u003cProductView\u003e ProductView { get; set; }\n\n    public SQLiteDb() : base(/** Optional path to file. **/)\n    {\n        if (UserVersion == 0)\n        {\n            CreateTable(\"Products\", c =\u003e new\n            {\n                Id = c.Column\u003cint\u003e(primaryKey:true),\n                Name = c.Column\u003cstring\u003e(nullable:false),\n                Price = c.Column\u003cdecimal\u003e()\n            },\n            t =\u003e new\n            {\n                UniqueProductNames = t.Unique(p =\u003e p.Name)\n            });\n\n            CreateTable(\"Purchases\", c =\u003e new\n            {\n                Id = c.Column\u003cint\u003e(primaryKey:true),\n                Customer = c.Column\u003cstring\u003e(nullable:false),\n                Date = c.Column\u003cDateTime\u003e(),\n                ProductId = c.Column\u003cint\u003e()\n            },\n            t =\u003e new\n            {\n                FK = t.ForeignKey(p =\u003e p.ProductId, \"Products\", new[]{ \"Id\" })\n            });\n\n            CreateView(\n                \"ProductView\",\n                Products.GroupJoin(Purchases, p =\u003e p.Id, p =\u003e p.ProductId, (product, purchases) =\u003e new ProductView\n                {\n                    Id = product.Id,\n                    Name = product.Name,\n                    Price = product.Price,\n                    PurchaseCount = purchases.Count()\n                })\n            );\n        }\n        UserVersion++;\n    }\n}\n```\n\nYou can insert data into tables like so, using the insert method of tables.\n\n```csharp\nusing(var db = new SQLiteDb())\n{\n    db.Products.Insert(new Product { Name = \"Laptop\", Price = 1499.99M });\n}\n```\n\nYou can query the database easily using the IQueryable methods or LINQ.\n\nMost methods are supported for querying, including Where, OrderBy, Join, GroupBy, Select, SelectMany, etc.\n\nNOTE: The database is not actually touched until enumeration happens, like when used in a foreach loop or any of the methods that do not return an IQueryable\u003c...\u003e are called e.g `ToList`, `ToArray`, `Single`, `First`, `Any` etc.\n\n```csharp\nusing(var db = new SQLiteDb())\n{\n    var result = db.Products.Where(p =\u003e p.Name.Length \u003c 10 \u0026\u0026 p.Price \u003e 19.99);\n    for (var product in result)\n    {\n        Console.WriteLine($\"Name={product.Name}, Price={product.Price}\");\n    }\n}\n```\n\nI don't know why but...  If you decide LINQ is not for you and you would rather type raw SQL.\nThere is the option of using the query method and specifying your own custom projector.\n\n```csharp\nusing(var db = new SQLiteDb())\n{\n    var result = db.Query(\"SELECT * FROM [Products]\", r =\u003e new\n    {\n         Name = r.Get\u003cstring\u003e(\"Name\"),\n         Price = r.Get\u003cdecimal\u003e(\"Price\")\n    });\n    for (var product in result)\n    {\n        Console.WriteLine($\"Item={item}\");\n    }\n}\n```\n\nIf you have a good reason for typing raw sql such as, a query that cannot be easily done with LINQ.\nBut still want to integrate some LINQ after, you still can.\nAnd the best part is that, it is still sent over to the database so it doesn't execute on the client side.\n\n```csharp\nusing (var db = new SQLiteDb())\n{\n    var result = db.Query(\"SELECT * FROM [Products]\", r =\u003e new\n    {\n         Name = r.Get\u003cstring\u003e(\"Name\"),\n         Price = r.Get\u003cdecimal\u003e(\"Price\")\n    })\n    .Where(p =\u003e p.Name.Length \u003c 10 \u0026\u0026 p.Price \u003e 19.99);\n\n    for (var product in result)\n    {\n        Console.WriteLine($\"Item={item}\");\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominaezzz%2Fsqlite-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominaezzz%2Fsqlite-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominaezzz%2Fsqlite-helper/lists"}