Skip to content

theandrunique/uniqmodel

Repository files navigation

UniqModel

Improves code readability and removes basic queries from the code.

Installing

To install the library, you can use NuGet and find the library named UniqModel.

.NET CLI

dotnet add package UniqModel

Installation from source

  1. Clone the project
git clone https://github.com/theandrunique/uniqmodel.git
  1. Navigate to the directory
cd uniqmodel/
  1. Compile the library
  • Run the solution file UniqModel.sln and compile the library
  • or use .NET CLI to compile
dotnet build
  1. Add a link to the created binary file in you project

Usage

// All models should inherit from BaseModel
class AccountTable : BaseModel
{
    // A primary key
    [PrimaryKey()]
    public int Id { get; set; }
    // Other fields
    [Field()]
    public string Nickname { get; set; }
    [Field()]
    public string NicknameShortcut { get; set; }
}

// Create an instance of Core
Core dbcore = new Core(DatabaseEngine.Sqlite, "Data Source=database.db");
// Create a session
// You should use a context manager
using (Session session = dbcore.CreateSession())
{
    // At this line, you already have a connection to the database and a transaction

    // Create an instance of the AccountTable class
    AccountTable account = new AccountTable()
    {
        Nickname = "a nickname",
        NicknameShortcut = "a shortcut",
    };

    // Add the object to the table
    session.Add(account);
}
// At this line, a new record has been added to the database
// The connection is closed, and the transaction is committed

License

This project is licensed under MIT license

About

A simple object mapper for .NET

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages