Info
Version: | 4.8.8 |
Author(s): | Ackara |
Last Update: | Sunday, July 16, 2017 |
.NET Fiddle: | Create the first Fiddle |
Project Url: | https://github.com/Ackara/Daterpillar |
NuGet Url: | https://www.nuget.org/packages/Acklann.Daterpillar |
Install
Install-Package Acklann.Daterpillar
dotnet add package Acklann.Daterpillar
paket add Acklann.Daterpillar
Acklann.Daterpillar Download (Unzip the "nupkg" after downloading)
Dependencies
- NETStandard.Library(>= 1.6.1)
- Microsoft.CSharp(>= 4.3.0)
- System.Xml.XmlSerializer(>= 4.3.0)
Tags
The library helps you to do the following.
* Generate a database schema from classes marked with specific attributes.
* Construct SQL queries.
* Construct SQL commands.
*******************
* USAGE *
*******************
1- Generating schemas.
The package ships with a msbuild target that runs before the build target. When executed the target will generate a xml file (<asseblyName>.schema.xml) in the project output directory. You can specify which classes are included in the xml file decorating them will attributes.
example:
[Table]
public class User
{
[Column] public int Id { get; set; }
[Column] public string Name { get; set; }
}
2- Constructing SQL queries
The Query class contain methods to help create SQL queries. There is also a Query<T> class that uses relfection to build the queries where as the Query class uses plain old string concatenation.
example:
var query = new Query<User>(Syntax.MySQL)
.SelectAll()
.Where(x=> x.Name == "john");
or
var query = new Query(Syntax.MySQL)
.SelectAll()
.Where("name='john'");
output: SELECT * FROM User Where Name='john';
3- Constructing SQL commands
The library contain several extension methods to generate commands from objects.
example:
var user = new User() { Id = 12, Name = "john" };
var insertCmd = user.ToInsertCommand();
output: INSERT INTO User (Id, Name) VALUES ('12', 'john');
var users = new User[] { ..
};
var insertCmd = users.ToInsertCommand();
output: output: INSERT INTO User (Id, Name) VALUES ('12', 'john'), ...