|
1 | 1 | # SQLiteSharp
|
2 |
| - A fork of SQLite-net. |
| 2 | + |
| 3 | +SQLiteSharp is a powerful library to help you access a SQLite database in C#. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Create tables from your .NET objects |
| 8 | +- Manage your database with SQL commands and No-SQL functions |
| 9 | +- Use synchronous and asynchronous APIs |
| 10 | +- Encrypt your database with a password or key |
| 11 | + |
| 12 | +## Background |
| 13 | + |
| 14 | +This project is based on [SQLite-net](https://github.com/praeclarum/sqlite-net) by Krueger Systems Inc. |
| 15 | + |
| 16 | +The purpose of SQLiteSharp is to provide improvements to the original library, which is outdated in many ways. |
| 17 | + |
| 18 | +## Example |
| 19 | + |
| 20 | +```cs |
| 21 | +public class ShopItem { |
| 22 | + [PrimaryKey, AutoIncrement] |
| 23 | + public long Id { get; set; } |
| 24 | + |
| 25 | + [NotNull] |
| 26 | + public string? ItemName { get; set; } |
| 27 | + |
| 28 | + public long Count { get; set; } |
| 29 | + |
| 30 | + [Ignore] |
| 31 | + public int SomethingToIgnore { get; set; } |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +```cs |
| 36 | +// Open a database connection |
| 37 | +using SQLiteConnection Connection = new("database.db"); |
| 38 | + |
| 39 | +// Create a table for a class |
| 40 | +Connection.CreateTable<ShopItem>(); |
| 41 | + |
| 42 | +// Delete all existing items in the table |
| 43 | +Connection.DeleteAll<ShopItem>(); |
| 44 | + |
| 45 | +// Insert items into the table |
| 46 | +Connection.Insert(new ShopItem() { |
| 47 | + ItemName = "Apple", |
| 48 | + Count = 10, |
| 49 | +}); |
| 50 | +Connection.Insert(new ShopItem() { |
| 51 | + ItemName = "Banana", |
| 52 | + Count = 5, |
| 53 | +}); |
| 54 | + |
| 55 | +// Find one item in the table matching a predicate |
| 56 | +ShopItem? Apple = Connection.Find<ShopItem>(ShopItem => ShopItem.ItemName == "Apple"); |
| 57 | +Assert.NotNull(Apple); |
| 58 | + |
| 59 | +// Delete an item from the table |
| 60 | +Connection.Delete(Apple); |
| 61 | + |
| 62 | +// Find several items in the table |
| 63 | +List<ShopItem> Bananas = Connection.Table<ShopItem>().Where(ShopItem => ShopItem.ItemName == "Banana").ToList(); |
| 64 | +Assert.Single(Bananas); |
| 65 | +``` |
0 commit comments