82 lines
2.0 KiB
Markdown
82 lines
2.0 KiB
Markdown
# Quick Start
|
|
|
|
## Install and Reference
|
|
|
|
Reference the `DynamORM` project or package from your application.
|
|
|
|
## Basic Setup
|
|
|
|
```csharp
|
|
using System.Data.SQLite;
|
|
using DynamORM;
|
|
|
|
var options =
|
|
DynamicDatabaseOptions.SingleConnection |
|
|
DynamicDatabaseOptions.SingleTransaction |
|
|
DynamicDatabaseOptions.SupportLimitOffset |
|
|
DynamicDatabaseOptions.SupportSchema;
|
|
|
|
using (var db = new DynamicDatabase(
|
|
SQLiteFactory.Instance,
|
|
"Data Source=app.db;",
|
|
options))
|
|
{
|
|
db.DumpCommands = true;
|
|
|
|
var users = db.Table("users");
|
|
var total = users.Count(columns: "id");
|
|
var first = users.First(columns: "id,first,last");
|
|
}
|
|
```
|
|
|
|
This setup mirrors `DynamORM.Tests/TestsBase.cs`.
|
|
|
|
## First Query (Dynamic API)
|
|
|
|
```csharp
|
|
using (var db = new DynamicDatabase(SQLiteFactory.Instance, "Data Source=app.db;", options))
|
|
{
|
|
var row = db.Table("users").Single(id: 19);
|
|
Console.WriteLine(row.first);
|
|
}
|
|
```
|
|
|
|
## First Query (Fluent Builder API)
|
|
|
|
```csharp
|
|
using (var db = new DynamicDatabase(SQLiteFactory.Instance, "Data Source=app.db;", options))
|
|
using (var query = db.From("users").Where("id", 19).SelectColumn("first"))
|
|
{
|
|
var first = query.ScalarAs<string>();
|
|
Console.WriteLine(first);
|
|
}
|
|
```
|
|
|
|
## First Query (Typed Fluent Syntax)
|
|
|
|
```csharp
|
|
using (var db = new DynamicDatabase(SQLiteFactory.Instance, "Data Source=app.db;", options))
|
|
{
|
|
var cmd = db.FromTyped<User>("u")
|
|
.SelectSql(u => u.Col(x => x.Code))
|
|
.WhereSql(u => u.Col(x => x.Id).Eq(19));
|
|
|
|
var value = cmd.ScalarAs<string>();
|
|
Console.WriteLine(value);
|
|
}
|
|
```
|
|
|
|
For multi-join typed queries, prefer `FromTypedScope(...)`. Full details are documented in [Typed Fluent Syntax](typed-fluent-syntax.md).
|
|
|
|
## Insert, Update, Delete
|
|
|
|
```csharp
|
|
var table = db.Table("users");
|
|
|
|
table.Insert(code: "201", first: "Juri", last: "Gagarin");
|
|
table.Update(values: new { first = "Yuri" }, where: new { code = "201" });
|
|
table.Delete(code: "201");
|
|
```
|
|
|
|
These forms are validated in `DynamORM.Tests/Modify/DynamicModificationTests.cs`.
|