This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sw = Stopwatch.StartNew(); | |
for (int i=0;i<10000;i++) InsertItem(i); | |
sw.Stop(); | |
Console.WriteLine($"Insert 10k: {sw.ElapsedMilliseconds}ms"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SQLite; | |
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "data.db"); | |
var conn = new SQLiteAsyncConnection(dbPath); | |
// Ensure table exists | |
await conn.CreateTableAsync<Product>(); | |
// Insert | |
await conn.InsertAsync(new Product { Name = "Laptop", Price = 1200 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SQLite; | |
public class Product | |
{ | |
[PrimaryKey, AutoIncrement] | |
public int Id { get; set; } | |
public string Name { get; set; } = ""; | |
public double Price { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet add package sqlite-net-pcl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LiteDB; | |
string path = Path.Combine(FileSystem.AppDataDirectory, "appdata.db"); | |
using var db = new LiteDatabase($"Filename={path};"); | |
// Get a collection (creates if missing) | |
var col = db.GetCollection<Note>("notes"); | |
// Insert | |
var note = new Note { Title = "Hello", Content = "World" }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Note | |
{ | |
public int Id { get; set; } // LiteDB uses int id by default | |
public string Title { get; set; } = ""; | |
public string Content { get; set; } = ""; | |
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet add package LiteDB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Realms; | |
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "realm.realm"); | |
var config = new RealmConfiguration(dbPath); | |
var realm = Realm.GetInstance(config); | |
// Create (within a write transaction) | |
realm.Write(() => | |
{ | |
realm.Add(new User { Name = "Alice", Age = 30 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Realms; | |
public class User : RealmObject | |
{ | |
[PrimaryKey] | |
public string Id { get; set; } = Guid.NewGuid().ToString(); | |
public string Name { get; set; } = ""; | |
public int Age { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet add package Realm |
NewerOlder