Skip to content

Commit 5356727

Browse files
authored
Use absolute paths in README Examples
Demonstrates the correct use of the ctors. Fixes praeclarum#602
1 parent c969ade commit 5356727

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class Stock
4343
{
4444
[PrimaryKey, AutoIncrement]
4545
public int Id { get; set; }
46-
[MaxLength(8)]
4746
public string Symbol { get; set; }
4847
}
4948

@@ -69,7 +68,10 @@ Both APIs are explained in the two sections below.
6968
Once you have defined your entity, you can automatically generate tables in your database by calling `CreateTable`:
7069

7170
```csharp
72-
var db = new SQLiteConnection("foofoo");
71+
// Get an absolute path to the database file
72+
var databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyData.db");
73+
74+
var db = new SQLiteConnection(databasePath);
7375
db.CreateTable<Stock>();
7476
db.CreateTable<Valuation>();
7577
```
@@ -90,7 +92,7 @@ Similar methods exist for `Update` and `Delete`.
9092
The most straightforward way to query for data is using the `Table` method. This can take predicates for constraining via WHERE clauses and/or adding ORDER BY clauses:
9193

9294
```csharp
93-
var conn = new SQLiteConnection("foofoo");
95+
var conn = new SQLiteConnection(databasePath);
9496
var query = conn.Table<Stock>().Where(v => v.Symbol.StartsWith("A"));
9597

9698
foreach (var stock in query)
@@ -129,7 +131,10 @@ will work for you.
129131
Once you have defined your entity, you can automatically generate tables by calling `CreateTableAsync`:
130132

131133
```csharp
132-
var conn = new SQLiteAsyncConnection("foofoo");
134+
// Get an absolute path to the database file
135+
var databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyData.db");
136+
137+
var conn = new SQLiteAsyncConnection(databasePath);
133138

134139
await conn.CreateTableAsync<Stock>();
135140

@@ -144,7 +149,7 @@ Stock stock = new Stock()
144149
Symbol = "AAPL"
145150
};
146151

147-
var conn = new SQLiteAsyncConnection("foofoo");
152+
var conn = new SQLiteAsyncConnection(databasePath);
148153

149154
await conn.InsertAsync(stock);
150155

@@ -158,7 +163,7 @@ you can add predictates for constraining via WHERE clauses and/or adding ORDER B
158163
retrieval methods - `ToListAsync`, `FirstAsync`, or `FirstOrDefaultAsync` - is called.
159164

160165
```csharp
161-
var conn = new SQLiteAsyncConnection("foofoo");
166+
var conn = new SQLiteAsyncConnection(databasePath);
162167
var query = await conn.Table<Stock>().Where(v => v.Symbol.StartsWith("A"));
163168

164169
var result = await query.ToListAsync();
@@ -173,7 +178,7 @@ operations provided by `InsertAsync` etc you can issue `ExecuteAsync` methods to
173178
Another helpful method is `ExecuteScalarAsync`. This allows you to return a scalar value from the database easily:
174179

175180
```csharp
176-
var conn = new SQLiteAsyncConnection("foofoo");
181+
var conn = new SQLiteAsyncConnection(databasePath);
177182

178183
var result = await conn.ExecuteScalarAsync<int>("select count(*) from Stock");
179184

0 commit comments

Comments
 (0)