All Projects → unosquare → litelib

unosquare / litelib

Licence: MIT License
A cool little wrapper in Entity Framework style for SQLite based on Dapper

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to litelib

imessage-chatbot
💬 Recurrent neural network -- generates messages in your style of speech! Trained on imessage data. Sqlite3, TensorFlow, Flask, Twilio SMS, AWS.
Stars: ✭ 33 (-47.62%)
Mutual labels:  sqlite3
json-sql-builder2
Level Up Your SQL-Queries
Stars: ✭ 59 (-6.35%)
Mutual labels:  sqlite3
JJMumbleBot
A plugin-based All-In-One mumble bot solution in python 3.7+ with extensive features and support for custom plugins.
Stars: ✭ 40 (-36.51%)
Mutual labels:  sqlite3
imgui
Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.
Stars: ✭ 348 (+452.38%)
Mutual labels:  sqlite3
CodexMicroORM
An alternative to ORM's such as Entity Framework, offers light-weight database mapping to your existing CLR objects. Visit "Design Goals" on GitHub to see more rationale and guidance.
Stars: ✭ 32 (-49.21%)
Mutual labels:  dapper
buke
full text search manpages
Stars: ✭ 27 (-57.14%)
Mutual labels:  sqlite3
electron-vue3-inote
使用electron11+vue3.x+ts的桌面端便笺项目,拥有漂亮的过渡动画效果,以富文本形式储存在本地,可多开输入窗口。(The desktop note project using electron11+vue3.x+ts has beautiful transition animation effects, stored locally in the form of rich text, and can open more input windows.)
Stars: ✭ 168 (+166.67%)
Mutual labels:  sqlite3
subtitles-view
基于javaFX的简单字幕处理桌面程序,集成在线翻译及语音转换
Stars: ✭ 368 (+484.13%)
Mutual labels:  sqlite3
SqlBatis
A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite etc..
Stars: ✭ 34 (-46.03%)
Mutual labels:  dapper
HashExploit
HashExpoit is Great Tool For Cracking Hash
Stars: ✭ 17 (-73.02%)
Mutual labels:  sqlite3
raspy-temperature-bot
This is a telegram bot hosted by a Raspberry Pi equipped with a temperature and humidity sensor. The bot is capable of sending plots and readings.
Stars: ✭ 31 (-50.79%)
Mutual labels:  sqlite3
GraphQL.RepoDB
A set of extensions for working with HotChocolate GraphQL and Database access with micro-orms such as RepoDb (or Dapper). This extension pack provides access to key elements such as Selections/Projections, Sort arguments, & Paging arguments in a significantly simplified facade so this logic can be leveraged in the Serivces/Repositories that enca…
Stars: ✭ 25 (-60.32%)
Mutual labels:  dapper
Send2KindleBot
Send to Kindle Telegram Bot
Stars: ✭ 111 (+76.19%)
Mutual labels:  sqlite3
purescript-node-sqlite3
Basic Purescript wrapper for node-sqlite3
Stars: ✭ 13 (-79.37%)
Mutual labels:  sqlite3
react-native-quick-sqlite
Fast SQLite for react-native.
Stars: ✭ 239 (+279.37%)
Mutual labels:  sqlite3
versatile-data-kit
Versatile Data Kit (VDK) is an open source framework that enables anybody with basic SQL or Python knowledge to create their own data pipelines.
Stars: ✭ 144 (+128.57%)
Mutual labels:  sqlite3
codeX
CodeX is a platform which converts code into easy to understand language.
Stars: ✭ 46 (-26.98%)
Mutual labels:  sqlite3
rsqlite3
sqlite3 Rewritten in RiiR Rust 🦀🦀🦀
Stars: ✭ 137 (+117.46%)
Mutual labels:  sqlite3
flaskbooks
A very light social network & RESTful API for sharing books using flask!
Stars: ✭ 19 (-69.84%)
Mutual labels:  sqlite3
grafana-sqlite-datasource
Grafana Plugin to enable SQLite as a Datasource
Stars: ✭ 57 (-9.52%)
Mutual labels:  sqlite3

Analytics Build Status Build status

LiteLib Logo

LiteLib

NOTE: We are not longer supporting this library.

A cool little wrapper for SQLite based on Dapper from Unosquare Labs -- It's also free and MIT-licensed

Please star this project if you find it useful!

LiteLib is a library that helps you get the job done quickly and easily by defining POCO classes and turns those classes into SQLite-mapped tables. You define a database context and LiteLib will automatically create the necessary SQLite tables for your context. You will then be able to easily query, insert, update or delete records from the database tables via the database context you just defined. LiteLib is not intended to be a replacement for Entity Framework, but rather a lighter alternative that saves you the work of creating tables, managing connection instances, logging SQL commands, and still allows you to use Dapper-style querying. So, if you like Entity Framework, but you prefer the speed of Dapper, and you are using SQLite for your project, then we hope you'll love LiteLib!

Stuff that LiteLib does very well:

  • Creates your database files and tables that map to classes and properties of your objects.
  • Automatically gives you access to predefined SELECT, UPDATE, INSERT and DELETE commands for each of your classes.
  • Automatically provides you with a simple and extensible data access layer.
  • Automatically manages connection instances.
  • Provides you with a log of SQL commands executed against your database file.

Stuff that LiteLib does not cover:

  • Migrations of any kind. You'll have to drop and recreate the DB file if your schema changes or migrate it manually.
  • Navigation properties or relationships. You'll have to implement and ensure consistency of data relations manually -- which BTW, it's not hard at all and lets you write faster, lighter code.
  • Automatic transactions or changesets. You'll have to BeginTransaction and Commit manually. The Data context class you define simply exposes the underlying Dapper connection.

Installation NuGet version

You can install LiteLib via NuGet Package Manager as follows:

PM> Install-Package LiteLib

LiteLib doesn't contains any SQLite interop or library, so you need to add it to your project. You can choose to a general bundle or custom bundle.

PM> Install-Package SQLitePCLRaw.bundle_green

If you are targeting only Linux environments (only .NET Core), you can use the sqlite3 bundle.

PM> Install-Package SQLitePCLRaw.bundle_e_sqlite3

Mono Users - If you are using Mono please target to NET461.

Usage

We designed LiteLib to be extremely easy to use. There are 3 steps you need to follow.

  1. Create your model classes. All model classes must extend from LiteModel. There are a few class and property attributes that LiteLib understands. See the examples below.
  2. Create your context class. It must extend LiteDbContext, and it must expose your LiteDbSet classes
  3. Use your context class. An example provided in the following section.

Example

Create your model class. Use the Table attribute to specify the name of the table you want to map your model to. Also, note we inherit from LiteModel. If you wish to create a unique index on a column, use the LiteUnique attribute on a property. If you wish to index a column, then simply use the LiteIndex attribute. Please note properties with complex datatypes will not be mapped to the database.

namespace Models
{
    using System;
    using System.ComponentModel.DataAnnotations.Schema;
    using Unosquare.Labs.LiteLib;

    [Table("ClientAccounts")]
    public class ClientAccount : LiteModel
    {
        [LiteUnique]
        public string Username { get; set; }

        public string Password { get; set; }

        [LiteIndex]
        public bool IsUsernameIP { get; set; }

        [LiteIndex]
        public long RelayServerId { get; set; }

        public DateTime DateCreatedUtc { get; set; }
        public DateTime LastAccessDateUtc { get; set; }
        public DateTime? LockedOutDateUtc { get; set; }
        public int FailedLoginAttempts { get; set; }
    }
}

Next, create your database context class. Extend LiteDbContext and expose any number of tables via properties of the generic type LiteDbSet<>. A context should always be disposable so the recommendation is to query your database inside a using block of statements.

namespace Models
{
    using Labs.LiteLib;

    public class AppDbContext : LiteDbContext
    {
        public AppDbContext()
            : base("mydbfile.db")
        {
            // map this context to the database file mydbfile.db
        }
        
        public virtual LiteDbSet<ClientAccount> ClientAccounts { get; set; }
    }
}

Finally, use your database context class. For example, to query your database by username asynchronously you can just do the following:

using (var db = new AppDbContext())
{
  var accounts = await db.ClientAccounts.SelectAsync(
      $"{nameof(ClientAccount.Username)} = @{nameof(ClientAccount.Username)}", 
      new { Username = "someuser" });
}

At this point, it should be easy for you to see that you can easily extend your data access logic via extension methods or by extending the LiteDbSet<> class and exposing it as a property in your database context class.

That's it! Happy coding!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].