Skip to content

Commit

Permalink
Add README and icon
Browse files Browse the repository at this point in the history
  • Loading branch information
asherber committed Oct 18, 2018
1 parent e6e2c61 commit e78aeb7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions PetaPoco.SqlKata.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PetaPoco.SqlKata", "PetaPoc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PetaPoco.SqlKata.Tests", "PetaPoco.SqlKata.Tests\PetaPoco.SqlKata.Tests.csproj", "{1BEE3731-A1F9-4099-A09B-109DC9248625}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{447D13E6-0522-4666-B601-F8B07249513B}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
![Icon](https://github.com/asherber/PetaPoco.SqlKata/raw/master/media/database-64.png)

# PetaPoco.SqlKata [![NuGet](https://img.shields.io/nuget/v/PetaPoco.SqlKata.svg)](https://nuget.org/packages/PetaPoco.SqlKata)

[PetaPoco](https://github.com/CollaboratingPlatypus/PetaPoco) is a handy micro-ORM, but the SQL builder that comes with it is extremely limited. This library lets you use [SqlKata](https://sqlkata.com) as a replacement query builder.

## Usage

```csharp
using (var db = new PetaPoco.Database(...))
{
// Build a SqlKata query
var query = new Query("MyTable")
.Where("Foo", "bar");

// Use the query in place of PetaPoco.Sql
var records = db.Fetch<MyClass>(query.ToSql());
}

```

Note that while PetaPoco has an `AutoGenerateSelect` feature that lets you omit the `SELECT` part of a query if your classes are set up correctly, SqlKata requires a table name in order to generate a query. If you try to use a `Query` without a table name, SqlKata will throw an `InvalidOperationException` when you call `ToSql()`.

### Compilers

Transforming a SqlKata `Query` into a SQL string requires a compiler. SqlKata comes with compilers for SQL Server, Postgres, MySql, and Firebird. For many simple queries, the generated SQL looks the same regardless of which compiler you use, but for certain queries the compiler will produce SQL tailored for that specific database.

By default, this library uses the SQL Server compiler. If you want to use a different compiler, there are a couple of different ways you can do so.

```csharp
// Specify the compiler for one SQL statement
var sql = query.ToSql(CompilerType.MySql);

// Change the default compiler for all SQL statements
SqlKataExtensions.DefaultCompiler = CompilerType.Postgres;
```

Binary file added media/database-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e78aeb7

Please sign in to comment.