Composable Queries
Definition of Composable Queries
-Composable methods are those you can chain to build the desired functionality out of smaller parts. -By passing functions as parameters, you can generate higher-order query operations. -Therefore, a composable query means you can do logics to compose just one database-SQL-query from multiple queryables. +
Basicly composable methods are those that you can chain together to build the desired functionality out of smaller parts. +By passing functions as parameters you are able to generate higher-order query operations. +Therefore composable query means that you can do logics to compose just one database-SQL-query from multiple queryables. By using composable queries you can shorten the Database transactions and keep the connection open a minimum of time.
One common anti-pattern is a trial to solve all the problems in the world by a single code. -So when you use this kind of feature to achieve "common logics", keep the software's maintainability in mind. +So when you use this kind of features to achieve "common logics", keep in mind the software mainainability. One solution is to add a database view and query that from SQLProvider.
Generate composable queries by using Linq IQueryable
-With composable queries, you can combine two queries in multiple ways, and one query can be used as the building block for the other query. -To see how this works, let's look at a simple query:
+With composable queries you can combine two queries in multiple ways, and one query can be used as the building block for the other query. +To see how this works, let’s look at a simple query:
let query1 =
query {
for customers in ctx.Main.Customers do
where (customers.ContactTitle = "USA")
select (customers)}
-The variable that is returned from the query is sometimes called a computation. If you write to evaluate +
The variable that is returned from the query is sometimes called a computation. If you write evaluate
(e.g. a foreach loop or |> Seq.toList
) and display the address field from the customers returned by this
computation, you see the following output:
GREAL|Great Lakes Food Market|Howard Snyder|Marketing Manager|2732 Baker Blvd.|Eugene|OR|97403|USA|(503) 555-7555|
@@ -301,13 +301,13 @@ Generate composable queries by using .NET LINQ functions with IQueryable.
-
The difference between IEnumerable and IQueryable is basically that IEnumerable is executed in the IL while IQueryable can be translated as an expression tree to some other context (like a database query).
-They are both lazy by nature, meaning they aren't evaluated until you enumerate the results.
-Here is an example:
-First, you have to add .NET LINQ:
+The difference between IEnumerable and IQueryable is basically that IEnumerable is executed in the IL while IQueryable can be translated as en expression tree to some other context (like a database query).
+They are both lazy by nature, meaning they aren’t evaluated until you enumerate over the results.
+Here an example:
+First you have to add .NET LINQ:
open System.Linq
-Then, you can define a composable query outside the main query
+Then you can define a composable query outside the main query
type CustomersEntity = sql.dataContext.``main.CustomersEntity``
let companyNameFilter inUse =
@@ -322,9 +322,9 @@ myFilter2
queryable
-(Let's assume that your inUse parameter is some complex data:
+
(Let's asume that your inUse some complex data:
E.g. Your sub-queries would come from other functions. Basic booleans you can just include to your where-clause)
-Then, you can create the main query
+Then you can create the main query
let query1 =
query {
for customers in ctx.Main.Customers do
@@ -335,9 +335,9 @@ let res = companyNameFilter true query1 |> Seq.toArray
Generate composable queries by using FSharp.Linq.ComposableQuery
-The SQLProvider also supports composable queries by integrating the following library FSharpLinqComposableQuery.
+
The SQLProvider also supports composable queries by integrating following library FSharpLinqComposableQuery.
You can read more about that library here: FSharp.Linq.ComposableQuery
-Because it is implemented in the SQLProvider, you don't need to add FSharpComposableQuery in your script.
+Because it is implemented in the SQLProvider you dont need to add FSharpComposableQuery in your script.
Example for using FSharpComposableQuery
let qry1 =
query { for u in dbContext.Users do
@@ -383,11 +383,11 @@ select (x.GetColumn<string> "CustomerId")
} |> Seq.head
-However, this is not recommended as one of the SQLProvider's key benefits is strong typing.
+However this is not recommended as one of the SQLProvider's key benefits is strong typing.
Generate composable queries from quotations
You can also construct composable queries using the F# quotation mechanism. For
example, if you need to select a filter function at runtime, you could write the
-filters as quotations, and then include them in a query like this:
+filters as quotations, and then include them into query like that:
let johnFilter = <@ fun (employee : sql.dataContext.``main.EmployeesEntity``) -> employee.FirstName = "John" @>
let pamFilter = <@ fun (employee : sql.dataContext.``main.EmployeesEntity``) -> employee.FirstName = "Pam" @>
@@ -399,7 +399,7 @@ select emp
} |> Seq.toArray
-Quotations are AST representations that the Linq-to-SQL translator can use.
+Quotations are AST representations which the Linq-to-SQL translator can use.
Multiple items
type LiteralAttribute =
inherit Attribute
@@ -484,10 +484,10 @@ 'T
val x: obj
type CustomersEntity = SqlDataProvider<...>.dataContext.main.CustomersEntity
diff --git a/core/constraints-relationships.html b/core/constraints-relationships.html
index da155571..a4638927 100644
--- a/core/constraints-relationships.html
+++ b/core/constraints-relationships.html
@@ -70,7 +70,7 @@
- How to contribute
+ How to make a contribution
@@ -250,12 +250,12 @@ SQLProvider
Constraints & Relationships
A typical relational database will have many connected tables and views
-through foreign key constraints. The SQL provider can show you these
+through foreign key constraints. The SQL provider is able to show you these
constraints on entities. They appear as properties named the same as the
constraint in the database.
You can gain access to these child or parent entities by simply enumerating
the property in question.
-While SQL provider automatically generates getters from foreign-key relations, it doesn't have (yet) any automatic support for creating a properly ordered graph of related entities in a single transaction. However, SQL provider submits entities to a database in the same order they were created. As long as you create entities in their dependency order, you won't get foreign-key constraint violations.
+While SQL provider automatically generates getters from foreign key relations, it doesn't have (yet) any automatic support for creating a properly ordered graph of related entities in a single transaction. However, SQL provider submits entities to a database in the same order they were created, which means that as long as you create entities in their dependency order, you won't get foreign key constraint violations.
diff --git a/core/contributing.html b/core/contributing.html
index 585c8962..b6416b61 100644
--- a/core/contributing.html
+++ b/core/contributing.html
@@ -7,17 +7,17 @@
-
-
- How to contribute
+ How to make a contribution
| SQLProvider
@@ -70,7 +70,7 @@
- How to contribute
+ How to make a contribution
@@ -248,36 +248,36 @@ SQLProvider
- How to contribute
+ How to make a contribution
This is how you can make a "pull request", to suggest your modifications to be accepted to the code base.
1. Download or clone the repository to your computer.
(Or take git pull
if you already have the repository.)
You need to get the .git folder inside the repository.
-If the download doesn't work, you can use clone, which creates a separate folder and downloads the repository:
+If the download doesn't work you can use clone, which creates a separate folder and downloads the repository:
git clone https://github.com/fsprojects/SQLProvider.git
2. Edit and Commit
Here are some tech details.
-Do the modifications and check the build and tests are working. Commit the changes to your local repository.
+Do the modifications, check the build and tests are working. Commit the modifications to your local repository.
3. Fork the GitHub repository.
This will "copy" the repository for your account.
4. Get Your Url
-In GitHub, go to your copy of the repository (under your profile, Repositories-tab) and under Download, get the repository URL, e.g. https://github.com/myname/SqlProvider.git
+In GitHub, go to your copy of the repository (under your profile, Repositories-tab) and under Download, get the repository url, e.g. https://github.com/myname/SqlProvider.git
5. Add a Remote
-With command line, add a remote to your repository URL:
+With command line, add a remote to your repository url:
git remote add myrepo https://github.com/myname/SqlProvider.git
-Use the name you want for the repository and note your GitHub account in the URL. You can check the remotes with git remote -v
.
+Use the name you want for repository and note your GitHub account in the url. You can check the remotes with git remote -v
.
6. Push to Your Remote
Push the latest version to your repository with
git push myrepo
. You should see the modifications in GitHub under your repository.
7. Create a Pull Request
-In GitHub, under your repository, press the Create pull request -button. By default, everything should be correct: The base-fork is the one to which you want to send the modifications, and the head fork is your fork, so follow the wizard.
+In GitHub under your repository press the Create pull request -button. By default, everything should be correct: Base-fork is the one where you want to send the modifications and head fork is your fork, so follow the wizard.
8. Done.
-Your pull request should be visible under the "Pull requests" -tab in the original repository. When you do more commits, you can ignore parts 3, 4 and 5, they has to be done just once.
+Your pull request should be visible under "Pull requests" -tab in original repository. When you do more commits, you can ignore parts 3, 4 and 5, they has to be done just once.
@@ -287,8 +287,8 @@ 8. Done.
On this page
-
-
- How to contribute
+
+ How to make a contribution
-
diff --git a/core/crud.html b/core/crud.html
index 6e0b0cf0..de5ed299 100644
--- a/core/crud.html
+++ b/core/crud.html
@@ -70,7 +70,7 @@
@@ -279,7 +279,7 @@ CRUD sample
Submit updates to the database
ctx.SubmitUpdates()
-After updating, your item (row) will have the Id property.
+After updating your item (row) will have the Id property.
You can also create with the longer ``Create(...)``(parameters)-method like this:
let emp = ctx.Main.Employees.``Create(FirstName, LastName)``("Don", "Syme")
@@ -364,7 +364,7 @@ CRUD sample
updateEmployee john
updateEmployee' john
-Finally it is also possible to specify a seq of string * obj
, which is precisely the
+
Finally it is also possible to specify a seq of string * obj
which is exactly the
output of .ColumnValues:
employees
|> Seq.map (fun x ->
@@ -377,7 +377,7 @@ CRUD sample
ctx.GetUpdates() // Get the updates
ctx.SubmitUpdates() // no record is added
-Inside SubmitUpdate the transaction is created by default TransactionOption, which is Required: Shares a transaction, if one exists, and creates a new transaction if necessary. So, if you have query-operation before SubmitUpdates, you should create your own transaction to wrap these into the same transaction.
+Inside SubmitUpdate the transaction is created by default TransactionOption, which is Required: Shares a transaction, if one exists, and creates a new transaction if necessary. So e.g. if you have query-operation before SubmitUpdates, you may want to create your own transaction to wrap these to the same transaction.
SQLProvider also supports async database operations:
ctx.SubmitUpdatesAsync() // |> Async.AwaitTask
@@ -401,7 +401,7 @@ OnConflict
ctx.SubmitUpdates()
Delete-query for multiple items
-To delete many items from a database table, DELETE FROM [dbo].[EMPLOYEES] WHERE (...)
, there is a way, although we don't recommend deleting items from a database. Instead, you should consider a deletion-flag column. You should also back up your database before trying this. Note that changes are immediately saved to the database even if you don't call ctx.SubmitUpdates()
.
+If you want to delete many items from a database table, DELETE FROM [dbo].[EMPLOYEES] WHERE (...)
, there is a way, although we don't recommend deleting items from a database. Instead you should consider a deletion-flag column. And you should backup your database before even trying this. Note that changes are immediately saved to the database even if you don't call ctx.SubmitUpdates()
.
query {
for c in ctx.Dbo.Employees do
where (...)
@@ -459,7 +459,7 @@ emp.SetColumn("BirthDate", DateTime.UtcNow.ToString("yyyy-MM-dd HH\:mm\:ss") |> box)
ctx.SubmitUpdates()
-SetColumn takes an object, giving you more control over the type serialization.
+SetColumn takes object, so you have more control over the type serialization.
Multiple items
type LiteralAttribute =
inherit Attribute
@@ -535,18 +535,18 @@ val now: DateTime
Multiple items
[<Struct>]
type DateTime =
- new: date: DateOnly * time: TimeOnly -> unit + 16 overloads
+ new: year: int * month: int * day: int -> unit + 10 overloads
member Add: value: TimeSpan -> DateTime
member AddDays: value: float -> DateTime
member AddHours: value: float -> DateTime
- member AddMicroseconds: value: float -> DateTime
member AddMilliseconds: value: float -> DateTime
member AddMinutes: value: float -> DateTime
member AddMonths: months: int -> DateTime
member AddSeconds: value: float -> DateTime
member AddTicks: value: int64 -> DateTime
- ...
--------------------
DateTime ()
(+0 other overloads)
DateTime(ticks: int64) : DateTime
(+0 other overloads)
DateTime(date: DateOnly, time: TimeOnly) : DateTime
(+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : DateTime
(+0 other overloads)
DateTime(date: DateOnly, time: TimeOnly, kind: DateTimeKind) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : DateTime
(+0 other overloads)
-property DateTime.Now: DateTime with get
+ member AddYears: value: int -> DateTime
+ ...
<summary>Represents an instant in time, typically expressed as a date and time of day.</summary>
--------------------
DateTime ()
(+0 other overloads)
DateTime(ticks: int64) : DateTime
(+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : DateTime
(+0 other overloads)
+property DateTime.Now: DateTime with get
<summary>Gets a <see cref="T:System.DateTime" /> object that is set to the current date and time on this computer, expressed as the local time.</summary>
<returns>An object whose value is the current local date and time.</returns>
val row: SqlDataProvider<...>.dataContext.main.OrdersEntity
SqlDataProvider<...>.dataContext.mainSchema.main.Orders.Create() : SqlDataProvider<...>.dataContext.main.OrdersEntity
SqlDataProvider<...>.dataContext.mainSchema.main.Orders.Create(data: Collections.Generic.IEnumerable<string * obj>) : SqlDataProvider<...>.dataContext.main.OrdersEntity
<summary>Item array of database columns:
</summary>
@@ -649,11 +649,7 @@
+ | DoNothing