Skip to content

Commit 6620a83

Browse files
committed
v0.2.3
1 parent 3f473ad commit 6620a83

12 files changed

+135
-272
lines changed

samples/MoviesAppSample/Converters/MoviesConverter10.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ internal sealed class MoviesConverter10: SQLiteDbConverter
77
{
88
public override Version Version { get; } = new("1.0");
99

10-
protected override bool PerformUpdate(SQLiteDbConnection connection)
10+
protected override bool PerformUpdate(SQLiteDbConnection connection, CancellationToken cancellationToken)
1111
{
12-
if (TryAddDbInfo(connection, Version.ToString()) == false)
12+
if (!TryAddDbInfo(connection, Version.ToString(), cancellationToken))
1313
{
1414
Debug.Assert(false);
1515
return false;
1616
}
17-
CreateTableMovies(connection);
18-
CreateTablePersons(connection);
17+
CreateTableMovies(connection, cancellationToken);
18+
CreateTablePersons(connection, cancellationToken);
1919
return true;
2020
}
2121

22-
private static void CreateTableMovies(SQLiteDbConnection connection)
22+
private static void CreateTableMovies(SQLiteDbConnection connection, CancellationToken cancellationToken)
2323
{
2424
connection.ExecuteNonQuery("""
2525
CREATE TABLE IF NOT EXISTS Movies (
2626
Id INTEGER PRIMARY KEY,
2727
Title TEXT NOT NULL,
2828
Description TEXT,
2929
DateReleased INTEGER NOT NULL);
30-
""");
30+
""", cancellationToken: cancellationToken);
3131
}
3232

33-
private static void CreateTablePersons(SQLiteDbConnection connection)
33+
private static void CreateTablePersons(SQLiteDbConnection connection, CancellationToken cancellationToken)
3434
{
3535
connection.ExecuteNonQuery("""
3636
CREATE TABLE IF NOT EXISTS Persons (
3737
Id INTEGER PRIMARY KEY,
3838
Name TEXT NOT NULL UNIQUE);
39-
""");
39+
""", cancellationToken: cancellationToken);
4040
}
4141
}
4242
}

samples/MoviesAppSample/Converters/MoviesConverter11.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ internal sealed class MoviesConverter11 : SQLiteDbConverter
66
{
77
public override Version Version { get; } = new("1.1");
88

9-
protected override bool PerformUpdate(SQLiteDbConnection connection)
9+
protected override bool PerformUpdate(SQLiteDbConnection connection, CancellationToken cancellationToken)
1010
{
11-
CreateTableMovieCasts(connection);
12-
CreateTableMovieDirectors(connection);
13-
CreateTableMovieWriters(connection);
11+
CreateTableMovieCasts(connection, cancellationToken);
12+
CreateTableMovieDirectors(connection, cancellationToken);
13+
CreateTableMovieWriters(connection, cancellationToken);
1414
return true;
1515
}
1616

17-
private static void CreateTableMovieCasts(SQLiteDbConnection connection)
17+
private static void CreateTableMovieCasts(SQLiteDbConnection connection, CancellationToken cancellationToken)
1818
{
1919
connection.ExecuteNonQuery("""
2020
CREATE TABLE IF NOT EXISTS MovieCasts (
@@ -24,10 +24,10 @@ FOREIGN KEY (MovieId) REFERENCES Movies(Id),
2424
FOREIGN KEY (PersonId) REFERENCES Persons(Id),
2525
PRIMARY KEY (MovieId, PersonId)
2626
);
27-
""");
27+
""", cancellationToken: cancellationToken);
2828
}
2929

30-
private static void CreateTableMovieDirectors(SQLiteDbConnection connection)
30+
private static void CreateTableMovieDirectors(SQLiteDbConnection connection, CancellationToken cancellationToken)
3131
{
3232
connection.ExecuteNonQuery("""
3333
CREATE TABLE IF NOT EXISTS MovieDirectors (
@@ -37,10 +37,10 @@ FOREIGN KEY (MovieId) REFERENCES Movies(Id),
3737
FOREIGN KEY (PersonId) REFERENCES Persons(Id),
3838
PRIMARY KEY (MovieId, PersonId)
3939
);
40-
""");
40+
""", cancellationToken : cancellationToken);
4141
}
4242

43-
private static void CreateTableMovieWriters(SQLiteDbConnection connection)
43+
private static void CreateTableMovieWriters(SQLiteDbConnection connection, CancellationToken cancellationToken)
4444
{
4545
connection.ExecuteNonQuery("""
4646
CREATE TABLE IF NOT EXISTS MovieWriters (
@@ -50,7 +50,7 @@ FOREIGN KEY (MovieId) REFERENCES Movies(Id),
5050
FOREIGN KEY (PersonId) REFERENCES Persons(Id),
5151
PRIMARY KEY (MovieId, PersonId)
5252
);
53-
""");
53+
""", cancellationToken: cancellationToken);
5454
}
5555
}
5656
}

samples/MoviesAppSample/DataAccess/MovieDal.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ValueTask<bool> DeleteMovieAsync(SQLiteDbContext? context, long id, Cance
3737

3838
using var command = ctx.Connection.CreateCommandDelete(TableName, "WHERE Id=@Id",
3939
DbType.Int64.CreateInputParam("@Id", id));
40-
int affected = ctx.Connection.ExecuteNonQuery(command, cancellationToken);
40+
int affected = ctx.Connection.ExecuteNonQuery(command, cancellationToken: cancellationToken);
4141
return affected == 1;
4242
}, cancellationToken);
4343
}
@@ -61,7 +61,7 @@ public ValueTask<bool> DeleteMoviesAsync(SQLiteDbContext? context, IEnumerable<l
6161
{
6262
bool result = await personDal.DeleteMoviePersonsAsync(ctx, id, cancellationToken);
6363
command.Parameters["@Id"].Value = id;
64-
affected += ctx.Connection.ExecuteNonQuery(command, cancellationToken);
64+
affected += ctx.Connection.ExecuteNonQuery(command, cancellationToken: cancellationToken);
6565
}
6666
return affected > 0;
6767
}, cancellationToken);
@@ -76,7 +76,7 @@ public ValueTask<bool> DeleteMoviesAsync(SQLiteDbContext? context, IEnumerable<l
7676
using var command = ctx.Connection.CreateCommandSelect(TableName, Columns, "WHERE Id=@Id LIMIT 1",
7777
DbType.Int64.CreateInputParam("@Id", id));
7878
MovieDto? dto = null;
79-
int count = ctx.Connection.ExecuteReader(command, Read, cancellationToken);
79+
int count = ctx.Connection.ExecuteReader(command, Read, cancellationToken: cancellationToken);
8080
Debug.Assert(1 == count);
8181
return dto;
8282

@@ -94,7 +94,7 @@ public ValueTask<List<MovieDto>> LoadMoviesAsync(SQLiteDbContext? context, Cance
9494
{
9595
using var command = ctx.Connection.CreateCommandSelect(TableName, Columns, "ORDER BY DateReleased");
9696
var list = new List<MovieDto>();
97-
int count = ctx.Connection.ExecuteReader(command, Read, cancellationToken);
97+
int count = ctx.Connection.ExecuteReader(command, Read, cancellationToken: cancellationToken);
9898
Debug.Assert(list.Count == count);
9999
return list;
100100

@@ -124,9 +124,10 @@ private static MovieDto ReadMovie(DbDataReader reader)
124124
if (dto.Id <= 0)
125125
{
126126
command = ctx.Connection.CreateCommandInsert(TableName, s_updateColumns,
127+
parameters: [
127128
DbType.String.CreateInputParam("@Title", dto.Title),
128129
DbType.String.CreateInputParam("@Description", dto.Description),
129-
DbType.DateTime.CreateInputParam("@DateReleased", dto.DateReleased));
130+
DbType.DateTime.CreateInputParam("@DateReleased", dto.DateReleased) ]);
130131
}
131132
else
132133
{
@@ -138,7 +139,7 @@ private static MovieDto ReadMovie(DbDataReader reader)
138139
}
139140
using (command)
140141
{
141-
int affected = ctx.Connection.ExecuteNonQuery(command, cancellationToken);
142+
int affected = ctx.Connection.ExecuteNonQuery(command, cancellationToken: cancellationToken);
142143
Debug.Assert(affected == 1);
143144
}
144145
if (dto.Id <= 0)

samples/MoviesAppSample/DataAccess/PersonDal.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ValueTask<bool> DeleteMoviePersonsAsync(SQLiteDbContext context, long mov
3636
{
3737
using var command = ctx.Connection.CreateCommandDelete(tableName, "WHERE MovieId=@MovieId",
3838
DbType.Int64.CreateInputParam("@MovieId", movieId));
39-
affected += ctx.Connection.ExecuteNonQuery(command, cancellationToken);
39+
affected += ctx.Connection.ExecuteNonQuery(command, cancellationToken: cancellationToken);
4040
}
4141
return affected > 0;
4242
}, cancellationToken);
@@ -79,7 +79,7 @@ void Read(SQLiteDataReader reader)
7979
reader.GetString(1)
8080
));
8181
}
82-
int count = ctx.Connection.ExecuteReader(command, Read, cancellationToken);
82+
int count = ctx.Connection.ExecuteReader(command, Read, cancellationToken: cancellationToken);
8383
Debug.Assert(list.Count == count);
8484
return list;
8585
}, cancellationToken);
@@ -171,11 +171,11 @@ public ValueTask<bool> SavePersonsAsync(SQLiteDbContext context, List<PersonDto>
171171
{
172172
var dto = dtos[i];
173173
commandInsert.Parameters["@Name"].Value = dto.Name;
174-
var id = ctx.Connection.ExecuteScalar(commandInsert, cancellationToken);
174+
var id = ctx.Connection.ExecuteScalar(commandInsert, cancellationToken: cancellationToken);
175175
if (id is null)//person alreasy exists
176176
{
177177
commandSelect.Parameters["@Name"].Value = dto.Name;
178-
id = ctx.Connection.ExecuteScalar(commandSelect, cancellationToken);
178+
id = ctx.Connection.ExecuteScalar(commandSelect, cancellationToken: cancellationToken);
179179
Debug.Assert(id is not null);
180180
}
181181
Debug.Assert(id is long);

samples/MoviesAppSample/Services/MoviesService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public async ValueTask<bool> DeleteMoviesAsync(List<Movie> moviesToDelete, Cance
3333
return await movieDal.DeleteMoviesAsync(null, moviesToDelete.Select(m => m.Id), cancellationToken);
3434
}
3535

36-
public async ValueTask<List<Movie>> GetAllMoviesAsync(CancellationToken cancellationToken = default)
36+
public async ValueTask<List<Movie>> GetAllMoviesAsync(CancellationToken cancellationToken)
3737
{
3838
using var connection = CreateConnection();
3939

@@ -42,7 +42,7 @@ public async ValueTask<List<Movie>> GetAllMoviesAsync(CancellationToken cancella
4242
using var dbContext = new SQLiteDbContext(connection);
4343
try
4444
{
45-
s_moviesConverters.Initialize(dbContext);
45+
s_moviesConverters.Initialize(dbContext, cancellationToken);
4646
using var movieDal = new MovieDal(CreateConnection);
4747
using var personDal = new PersonDal(CreateConnection);
4848
var movieDtos = await movieDal.LoadMoviesAsync(dbContext, cancellationToken);
@@ -84,13 +84,13 @@ private string GetMoviesConnectionString()
8484
return csb.ConnectionString;
8585
}
8686

87-
public ValueTask InitializeAsync(CancellationToken cancellationToken = default)
87+
public ValueTask InitializeAsync(CancellationToken cancellationToken)
8888
{
8989
s_moviesConverters.Initialize(CreateConnection, cancellationToken);
9090
return default;
9191
}
9292

93-
public async ValueTask<bool> SaveMovieAsync(Movie movie, CancellationToken cancellationToken = default)
93+
public async ValueTask<bool> SaveMovieAsync(Movie movie, CancellationToken cancellationToken)
9494
{
9595
using var connection = CreateConnection();
9696

@@ -99,7 +99,7 @@ public async ValueTask<bool> SaveMovieAsync(Movie movie, CancellationToken cance
9999
using var dbContext = new SQLiteDbContext(connection);
100100
try
101101
{
102-
s_moviesConverters.Initialize(dbContext);
102+
s_moviesConverters.Initialize(dbContext, cancellationToken);
103103
using var movieDal = new MovieDal(CreateConnection);
104104
using var personDal = new PersonDal(CreateConnection);
105105

src/NuExt.System.Data.SQLite.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ System.Data.SQLite.SQLiteDbConnection
1414
System.Data.SQLite.SQLiteDbContext
1515
System.Data.SQLite.SQLiteDbConverter
1616
System.Data.SQLite.SQLiteDbTransaction</Description>
17-
<Version>0.2.2</Version>
17+
<Version>0.2.3</Version>
1818
<RootNamespace />
1919
<GenerateDocumentationFile>True</GenerateDocumentationFile>
2020
<NoWarn>$(NoWarn);1591</NoWarn>
@@ -28,7 +28,7 @@ System.Data.SQLite.SQLiteDbTransaction</Description>
2828
</ItemGroup>
2929

3030
<ItemGroup Condition="'$(UseNuExtPackages)' == 'true'">
31-
<PackageReference Include="NuExt.System.Data" Version="0.2.2" />
31+
<PackageReference Include="NuExt.System.Data" Version="0.2.3" />
3232
</ItemGroup>
3333

3434
<ItemGroup Condition="'$(UseNuExtPackages)' == 'false'">

src/System/Data/SQLite/SQLiteDbConnection.Adapters.cs

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ public SQLiteDataAdapter CreateAdapter(SQLiteCommand command)
3434
#region Select
3535

3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37-
public DataTable Select(string tableName, IEnumerable<string> fields, string? expr, params SQLiteParameter[] parameters)
38-
{
39-
return Select(tableName, fields, expr, default, parameters);
40-
}
41-
42-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
43-
public DataTable Select(string tableName, IEnumerable<string> fields, string? expr, CancellationToken cancellationToken, params SQLiteParameter[] parameters)
37+
public DataTable Select(string tableName, IEnumerable<string> fields, string? expr = null, CancellationToken cancellationToken = default, params SQLiteParameter[] parameters)
4438
{
4539
#if NET8_0_OR_GREATER
4640
ArgumentException.ThrowIfNullOrEmpty(tableName);
@@ -51,13 +45,7 @@ public DataTable Select(string tableName, IEnumerable<string> fields, string? ex
5145
}
5246

5347
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54-
public DataTable Select(string sql, params SQLiteParameter[] parameters)
55-
{
56-
return Select(sql, default, parameters);
57-
}
58-
59-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
60-
public DataTable Select(string sql, CancellationToken cancellationToken, params SQLiteParameter[] parameters)
48+
public DataTable Select(string sql, CancellationToken cancellationToken = default, params SQLiteParameter[] parameters)
6149
{
6250
#if NET8_0_OR_GREATER
6351
ArgumentException.ThrowIfNullOrEmpty(sql);
@@ -67,13 +55,7 @@ public DataTable Select(string sql, CancellationToken cancellationToken, params
6755
return Select(CreateCommand(sql, parameters), cancellationToken);
6856
}
6957

70-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
71-
public DataTable Select(SQLiteCommand command)
72-
{
73-
return Select(command, default);
74-
}
75-
76-
public DataTable Select(SQLiteCommand command, CancellationToken cancellationToken)
58+
public DataTable Select(SQLiteCommand command, CancellationToken cancellationToken = default)
7759
{
7860
#if NET6_0_OR_GREATER
7961
ArgumentNullException.ThrowIfNull(command);
@@ -100,13 +82,7 @@ public DataTable Select(SQLiteCommand command, CancellationToken cancellationTok
10082
#region SelectForUpdate
10183

10284
[MethodImpl(MethodImplOptions.AggressiveInlining)]
103-
public (SQLiteDataAdapter, DataTable) SelectForUpdate(string tableName, IEnumerable<string> fields, string? expr, bool generateCommands, params SQLiteParameter[] parameters)
104-
{
105-
return SelectForUpdate(tableName, fields, expr, generateCommands, default, parameters);
106-
}
107-
108-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
109-
public (SQLiteDataAdapter, DataTable) SelectForUpdate(string tableName, IEnumerable<string> fields, string? expr, bool generateCommands, CancellationToken cancellationToken, params SQLiteParameter[] parameters)
85+
public (SQLiteDataAdapter, DataTable) SelectForUpdate(string tableName, IEnumerable<string> fields, string? expr = null, bool generateCommands = true, CancellationToken cancellationToken = default, params SQLiteParameter[] parameters)
11086
{
11187
#if NET8_0_OR_GREATER
11288
ArgumentException.ThrowIfNullOrEmpty(tableName);
@@ -117,13 +93,7 @@ public DataTable Select(SQLiteCommand command, CancellationToken cancellationTok
11793
}
11894

11995
[MethodImpl(MethodImplOptions.AggressiveInlining)]
120-
public (SQLiteDataAdapter, DataTable) SelectForUpdate(string sql, bool generateCommands, params SQLiteParameter[] parameters)
121-
{
122-
return SelectForUpdate(sql, generateCommands, default, parameters);
123-
}
124-
125-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
126-
public (SQLiteDataAdapter, DataTable) SelectForUpdate(string sql, bool generateCommands, CancellationToken cancellationToken, params SQLiteParameter[] parameters)
96+
public (SQLiteDataAdapter, DataTable) SelectForUpdate(string sql, bool generateCommands = true, CancellationToken cancellationToken = default, params SQLiteParameter[] parameters)
12797
{
12898
#if NET8_0_OR_GREATER
12999
ArgumentException.ThrowIfNullOrEmpty(sql);
@@ -133,13 +103,7 @@ public DataTable Select(SQLiteCommand command, CancellationToken cancellationTok
133103
return SelectForUpdate(CreateCommand(sql, parameters), generateCommands, cancellationToken);
134104
}
135105

136-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
137-
public (SQLiteDataAdapter, DataTable) SelectForUpdate(SQLiteCommand command, bool generateCommands)
138-
{
139-
return SelectForUpdate(command, generateCommands, default);
140-
}
141-
142-
public (SQLiteDataAdapter, DataTable) SelectForUpdate(SQLiteCommand command, bool generateCommands, CancellationToken cancellationToken)
106+
public (SQLiteDataAdapter, DataTable) SelectForUpdate(SQLiteCommand command, bool generateCommands = true, CancellationToken cancellationToken = default)
143107
{
144108
#if NET6_0_OR_GREATER
145109
ArgumentNullException.ThrowIfNull(command);
@@ -178,13 +142,7 @@ public DataTable Select(SQLiteCommand command, CancellationToken cancellationTok
178142

179143
#region Fill
180144

181-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
182-
public void Fill(SQLiteDataAdapter adapter, DataTable table)
183-
{
184-
Fill(adapter, table, default);
185-
}
186-
187-
public void Fill(SQLiteDataAdapter adapter, DataTable table, CancellationToken cancellationToken)
145+
public void Fill(SQLiteDataAdapter adapter, DataTable table, CancellationToken cancellationToken = default)
188146
{
189147
#if NET6_0_OR_GREATER
190148
ArgumentNullException.ThrowIfNull(adapter);
@@ -201,12 +159,7 @@ public void Fill(SQLiteDataAdapter adapter, DataTable table, CancellationToken c
201159

202160
#region Update
203161

204-
public int Update(SQLiteDataAdapter adapter, DataTable table)
205-
{
206-
return Update(adapter, table, default);
207-
}
208-
209-
public int Update(SQLiteDataAdapter adapter, DataTable table, CancellationToken cancellationToken)
162+
public int Update(SQLiteDataAdapter adapter, DataTable table, CancellationToken cancellationToken = default)
210163
{
211164
#if NET6_0_OR_GREATER
212165
ArgumentNullException.ThrowIfNull(adapter);

0 commit comments

Comments
 (0)