Code Monkey home page Code Monkey logo

postulate.lite's Introduction

Postulate.Lite

Build status

I wanted to build an ORM that has no particular root type dependency (i.e. Record) and that would work as IDbConnection extension methods, the way Dapper.SimpleCRUD does.

I intend to support Model Merge capability eventually, but at the moment I'm just getting my new core Crud methods working.

Postulate.Lite will support both SQL Server and MySQL. Model merge capability is back-burnured for MySQL, but Crud methods have full parity between both databases.

Please see the Wiki for more info.

Nuget

  • SQL Server package: Postulate.Lite.SqlServer
  • MySql package: Postulate.Lite.MySql

How to Use

  • Create any number of model classes that correspond to your database tables. They can be POCO, but added functionality is available if you inherit from Postulate.Lite.Core.Record. The only design requirement for Postulate.Lite model classes is that either they have an [Identity] attribute that defines the primary key property, or they have a property called Id with no particular attribute decoration.

  • For Sql Server, Postulate.Lite supports int, Guid, and long identity types. MySql currently supports int. When creating your model classes, decide on an identity type and be consistent across all your model classes.

  • Open your IDbConnection object in whatever way is appropriate for your application, normally within a using block.

  • Use any of the Postulate.Lite Crud extension methods of IDbConnection: Find, FindWhere, Save, Insert, Update, Delete, Exists, and ExistsWhere. They all accept a TModel generic argument corresponding to your model class. In the SQL Server package, there are three different namespaces with a static ConnectionExtensions class that provides the crud methods: Postulate.Lite.SqlServer.IntKey, LongKey, and GuidKey, so use the namespace appropriate to the identity type you chose above.

  • All of the Crud methods accept an IUser optional argument you can use to pass the current user name and access to the user's local time. This argument takes effect if your model class is based on Record (see above), which offers a number of overrides for checking permissions and executing row-level events, looking up foreign keys, among other things.

Examples

A simple find using the Find method:

using (var cn = GetConnection())
{
  var e = cn.Find<Employee>(2322);
  Console.WriteLine(e.FirstName);
}

Find using criteria with the FindWhere method:

using (var cn = GetConnection())
{
  var e = cn.FindWhere(new Employee() { OrganizationId = 12, Number = 3988 });
  Console.WriteLine(e.FirstName);
}

Create and save a record with the Save method.

using (var cn = GetConnection())
{
  var e = new Employee()
  {
    FirstName = "Thomas",
    LastName = "Whoever",
    HireDate = new DateTime(2012, 1, 1)
  };
  cn.Save<Employee>(e);
  Console.WriteLine(e.Id.ToString());
}

Extending Postulate.Lite

To implement Postulate.Lite for a particular database, inherit from abstract class CommandProvider<TKey> and implement its various abstract methods that generate SQL for Crud actions. The TKey generic argument specifies the identity (primary key) type used with your modeal classes. The default SQL Server implementation assumes an int primary key type. To implement long or Guid primary key types, you'd need to derive a new class from CommandProvider with your desired key type.

postulate.lite's People

Contributors

adamfoneil avatar

Watchers

Drew Lloyd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.