Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Sep 30, 2024
2 parents 1a0165c + 0aa8b64 commit 614496d
Show file tree
Hide file tree
Showing 21 changed files with 679 additions and 192 deletions.
28 changes: 11 additions & 17 deletions MyApp/_pages/autoquery/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,19 @@ Just as you can create [Custom AutoQuery Implementations](/autoquery/rdbms.html#
you can also override AutoQuery CRUD implementations by creating implementations with AutoQuery CRUD Request DTOs and calling the relevate `IAutoQueryDb` method, e.g:

```csharp
public class MyCrudServices : Service
public class MyCrudServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public object Post(CreateRockstar request) => AutoQuery.Create(request, base.Request);
public object Put(UpdateRockstar request) => AutoQuery.Update(request, base.Request);
public object Delete(DeleteRockstar request) => AutoQuery.Delete(request, base.Request);
public object Post(CreateRockstar request) => autoQuery.Create(request, base.Request);
public object Put(UpdateRockstar request) => autoQuery.Update(request, base.Request);
public object Delete(DeleteRockstar request) => autoQuery.Delete(request, base.Request);
}

// Async
public class MyCrudServices : Service
public class MyCrudServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public Task<object> Post(CreateRockstar request) => AutoQuery.CreateAsync(request, base.Request);
public Task<object> Put(UpdateRockstar request) => AutoQuery.UpdateAsync(request, base.Request);
public Task<object> Delete(DeleteRockstar request) => AutoQuery.DeleteAsync(request, base.Request);
public Task<object> Post(CreateRockstar request) => autoQuery.CreateAsync(request, base.Request);
public Task<object> Put(UpdateRockstar request) => autoQuery.UpdateAsync(request, base.Request);
public Task<object> Delete(DeleteRockstar request) => autoQuery.DeleteAsync(request, base.Request);
}
```

Expand Down Expand Up @@ -490,15 +486,13 @@ have them you'd need to provide custom implementations that can delegate to thei

```csharp
[ConnectionInfo(NamedConnection = MyDatabases.Reporting)]
public class MyReportingServices : Service
public class MyReportingServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public Task<object> Any(CreateConnectionInfoRockstar request) =>
AutoQuery.CreateAsync(request, Request);
autoQuery.CreateAsync(request, Request);

public Task<object> Any(UpdateConnectionInfoRockstar request) =>
AutoQuery.UpdateAsync(request, Request);
autoQuery.UpdateAsync(request, Request);
}
```

Expand Down
10 changes: 4 additions & 6 deletions MyApp/_pages/autoquery/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,13 @@ public class CustomRockstar
}

// Override with custom implementation
public class MyQueryServices : Service
public class MyQueryServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public async Task<object> Any(QueryRockstarAlbums query)
{
using var db = AutoQuery.GetDb(query, base.Request);
var q = AutoQuery.CreateQuery(query, base.Request, db);
return await AutoQuery.ExecuteAsync(query, q, base.Request, db);
using var db = autoQuery.GetDb(query, base.Request);
var q = autoQuery.CreateQuery(query, base.Request, db);
return await autoQuery.ExecuteAsync(query, q, base.Request, db);
}
}
```
Expand Down
48 changes: 19 additions & 29 deletions MyApp/_pages/autoquery/rdbms.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,23 @@ The behavior of queries can be completely customized by simply providing your ow

```csharp
// Override with custom implementation
public class MyQueryServices : Service
public class MyQueryServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

// Sync
public object Any(FindMovies query)
{
using var db = AutoQuery.GetDb(query, base.Request);
var q = AutoQuery.CreateQuery(query, base.Request, db);
return AutoQuery.Execute(query, q, base.Request, db);
using var db = autoQuery.GetDb(query, base.Request);
var q = autoQuery.CreateQuery(query, base.Request, db);
return autoQuery.Execute(query, q, base.Request, db);
}

// Async
public async Task<object> Any(QueryRockstars query)
{
using var db = AutoQuery.GetDb(query, base.Request);
var q = AutoQuery.CreateQuery(query, base.Request, db);
return await AutoQuery.ExecuteAsync(query, q, base.Request, db);
}
using var db = autoQuery.GetDb(query, base.Request);
var q = autoQuery.CreateQuery(query, base.Request, db);
return await autoQuery.ExecuteAsync(query, q, base.Request, db);
}
}
```

Expand Down Expand Up @@ -1078,14 +1076,12 @@ public class QueryPosts : QueryDb<Post>
}

[CacheResponse(Duration = 600)]
public class PostPublicServices : PostServicesBase
public class PostPublicServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public object Any(QueryPosts request)
{
using var db = AutoQuery.GetDb(query, base.Request);
var q = AutoQuery.CreateQuery(query, base.Request, db) //Populated SqlExpression
using var db = autoQuery.GetDb(query, base.Request);
var q = autoQuery.CreateQuery(query, base.Request, db) //Populated SqlExpression
q.Where(x => x.Deleted == null);

Expand Down Expand Up @@ -1197,11 +1193,9 @@ E.g. This implementation applies the `[ConnectionInfo]` behavior to all its Serv

```csharp
[ConnectionInfo(NamedConnection = "Reporting")]
public class MyReportingServices : Service
public class MyReportingServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public Task<object> Any(CreateReport request) => AutoQuery.CreateAsync(request, base.Request);
public Task<object> Any(CreateReport request) => autoQuery.CreateAsync(request,base.Request);
}
```

Expand Down Expand Up @@ -1338,15 +1332,13 @@ Where it's also queryable with:
We've already covered some of extensibility options with Customizable **QueryDbFields** and **Implicit Conventions**, the most customizable would be to override the default implementation with a custom one, e.g:

```csharp
public class MyQueryServices : Service
public class MyQueryServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

//Override with custom implementation
public object Any(FindMovies dto)
{
var q = AutoQuery.CreateQuery(dto, Request.GetRequestParams(), base.Request);
return AutoQuery.Execute(dto, q, base.Request);
var q = autoQuery.CreateQuery(dto, Request.GetRequestParams(), base.Request);
return autoQuery.Execute(dto, q, base.Request);
}
}
```
Expand Down Expand Up @@ -1430,19 +1422,17 @@ Plugins.Add(new AutoQueryFeature {
It also wont generate implementations for custom AutoBatch implementations, e.g. you can add a custom implementation that does what the generated implementation would've done and execute using the same DB Connection and Transaction with:

```csharp
public class CustomAutoQueryServices : Service
public class CustomAutoQueryServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public object Any(CreateItem[] requests)
{
using var db = AutoQuery.GetDb<Item>(Request);
using var db = autoQuery.GetDb<Item>(Request);
using var dbTrans = db.OpenTransaction();

var results = new List<object>();
foreach (var request in requests)
{
var response = await AutoQuery.CreateAsync(request, Request, db);
var response = await autoQuery.CreateAsync(request, Request, db);
results.Add(response);
}

Expand Down
14 changes: 7 additions & 7 deletions MyApp/_pages/background-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,31 +635,31 @@ public class NotifyCheckUrlsCommand(IHttpClientFactory clientFactory)
`ReplyTo` can be any URL which by default will have the result POST'ed back to the URL with a JSON
Content-Type. Typically URLs will contain a reference Id so external clients can correlate a callback
with the internal process that initiated the job. If the callback API is publicly available you'll
want to use an internal Id that can't be guessed so the callback can't be spoofed, like a Guid, e.g:
want to use an internal Id that can't be guessed (like a Guid) so the callback can't be spoofed, e.g:

`$"https://api.example.com?refId={RefId}"`
`$"https://api.example.com/callback?refId={RefId}"`

If needed the callback URL can be customized on how the HTTP Request callback is sent.

If the URL contains a space, the text before the space is treated as the HTTP method:

`"PUT https://api.example.com"`
`"PUT https://api.example.com/callback"`

If the auth part contains a colon `:` it's treated as Basic Auth:

`"username:password@https://api.example.com"`
`"username:password@https://api.example.com/callback"`

If name starts with `http.` sends a HTTP Header

`"http.X-API-Key:myApiKey@https://api.example.com"`
`"http.X-API-Key:myApiKey@https://api.example.com/callback"`

Otherwise it's sent as a Bearer Token:

`"myToken123@https://api.example.com"`
`"myToken123@https://api.example.com/callback"`

Bearer Token or HTTP Headers starting with `$` is substituted with Environment Variable if exists:

`"$API_TOKEN@https://api.example.com"`
`"$API_TOKEN@https://api.example.com/callback"`

When needed headers, passwords and tokens can be URL encoded if they contain any delimiter characters.

Expand Down
6 changes: 2 additions & 4 deletions MyApp/_pages/releases/v4_0_56.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,8 @@ public class QueryCustomers : QueryDb<Customer>
public int? OrAgeOlderThan { get; set; }
}

public class AutoQueryRDBMSServices : Service
public class AutoQueryRDBMSServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }
...
}

Expand All @@ -739,9 +738,8 @@ public class QueryCustomers : QueryData<Customer>
public int? OrAgeOlderThan { get; set; }
}

public class AutoQueryDataServices : Service
public class AutoQueryDataServices(IAutoQueryData autoQuery) : Service
{
public IAutoQueryData AutoQuery { get; set; }
...
}
```
Expand Down
24 changes: 10 additions & 14 deletions MyApp/_pages/releases/v5_09.md
Original file line number Diff line number Diff line change
Expand Up @@ -1390,15 +1390,13 @@ have them you'd need to provide custom implementations that can delegate to thei

```csharp
[ConnectionInfo(NamedConnection = MyDatabases.Reporting)]
public class MyReportingServices : Service
public class MyReportingServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public Task<object> Any(CreateConnectionInfoRockstar request) =>
AutoQuery.CreateAsync(request, Request);
autoQuery.CreateAsync(request, Request);

public Task<object> Any(UpdateConnectionInfoRockstar request) =>
AutoQuery.UpdateAsync(request, Request);
autoQuery.UpdateAsync(request, Request);
}
```

Expand Down Expand Up @@ -3441,10 +3439,8 @@ E.g. This implementation applies the `[ConnectionInfo]` behavior to all its Serv

```csharp
[ConnectionInfo(NamedConnection = "Reporting")]
public class MyReportingServices : Service
public class MyReportingServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public Task<object> Any(CreateReport request) => AutoQuery.CreateAsync(request, base.Request);
}
```
Expand All @@ -3458,9 +3454,9 @@ There's a minor optimization existing custom AutoQuery implementations can do by
// Sync
public object Any(QueryRockstars query)
{
using var db = AutoQuery.GetDb(query, base.Request);
var q = AutoQuery.CreateQuery(query, base.Request, db);
return await AutoQuery.Execute(query, q, base.Request, db);
using var db = autoQuery.GetDb(query, base.Request);
var q = autoQuery.CreateQuery(query, base.Request, db);
return await autoQuery.Execute(query, q, base.Request, db);
}
```

Expand All @@ -3470,9 +3466,9 @@ Another optimization if using SQL Server or PostgreSQL RDBMS's is to refactor it
// Async
public async Task<object> Any(QueryRockstars query)
{
using var db = AutoQuery.GetDb(query, base.Request);
var q = AutoQuery.CreateQuery(query, base.Request, db);
return await AutoQuery.ExecuteAsync(query, q, base.Request, db);
using var db = autoQuery.GetDb(query, base.Request);
var q = autoQuery.CreateQuery(query, base.Request, db);
return await autoQuery.ExecuteAsync(query, q, base.Request, db);
}
```

Expand Down
8 changes: 3 additions & 5 deletions MyApp/_pages/releases/v5_12.md
Original file line number Diff line number Diff line change
Expand Up @@ -2327,19 +2327,17 @@ Plugins.Add(new AutoQueryFeature {
It also wont generate implementations for custom AutoBatch implementations, e.g. you can add a custom implementation that does what the generated implementation would've done and execute using the same DB Connection and Transaction with:

```csharp
public class CustomAutoQueryServices : Service
public class CustomAutoQueryServices(IAutoQueryDb autoQuery) : Service
{
public IAutoQueryDb AutoQuery { get; set; }

public object Any(CreateItem[] requests)
{
using var db = AutoQuery.GetDb<Item>(Request);
using var db = autoQuery.GetDb<Item>(Request);
using var dbTrans = db.OpenTransaction();

var results = new List<object>();
foreach (var request in requests)
{
var response = await AutoQuery.CreateAsync(request, Request, db);
var response = await autoQuery.CreateAsync(request, Request, db);
results.Add(response);
}

Expand Down
Loading

0 comments on commit 614496d

Please sign in to comment.