🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

QuickAPI.Database

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

QuickAPI.Database

Database components for QuickAPI including data models, attributes, and EF Core extensions

1.0.0
NuGet
Version published
Maintainers
1
Created
Source

QuickAPI.Database

Overview

QuickAPI.Database is a foundational library for database components in QuickAPI. It provides a set of base models, a core DbContext implementation, an interface for tenant-based multi-tenancy support, and custom data annotations for EF Core models.

This package is designed to be used in backend projects that require database operations with Entity Framework Core.

Features

  • Base Models: Provides a BaseModel class with common fields such as Id, CreatedAt, ModifiedAt, and IsDeleted.
  • Custom EF Core Extensions: Includes helpers for applying custom attributes and constraints on entity properties.
  • Tenant Support: Implements ITenantModel to enforce tenant-based filtering.
  • Base DbContext: A BaseContext class that automatically applies query filters, tracks modifications, and handles tenant-aware queries.
  • Custom Data Annotations: Attributes for defining SQL default values, computed columns, primary keys, and constraint indexes.

Installation

To install this package via NuGet:

dotnet add package QuickAPI.Database

This package requires EF Core. Ensure you have installed Microsoft.EntityFrameworkCore in your project.

Usage

BaseModel

All entity models should inherit from BaseModel to get common fields and automatic tracking.

using QuickAPI.Database.DataModels;

public class Product : BaseModel
{
    public decimal Price { get; set; }
}

Tenant Support

To support multi-tenancy, a model should implement ITenantModel:

using QuickAPI.Database.DataModels;

public class Order : BaseModel, ITenantModel
{
    public Guid TenantId { get; set; }
    public decimal TotalAmount { get; set; }
}

BaseContext

The BaseContext class automatically applies:

  • Tenant-based filtering using _tenantProvider
  • Timestamps for created and modified fields
  • Cascade delete restrictions for safer operations

Example Usage:

using Microsoft.EntityFrameworkCore;
using QuickAPI.Database.Data;

public class AppDbContext : BaseContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options, ITenantProvider tenantProvider)
        : base(options, tenantProvider)
    {
    }

    public DbSet<Product> Products { get; set; }
}

Applying Custom Data Annotations

Use built-in attributes for defining SQL constraints directly in your models.

Default Values

[SqlDefaultValue("getdate()")]
public DateTimeOffset CreatedAt { get; set; }

Computed Columns

[SqlComputed("Price * Quantity", stored: true)]
public decimal TotalCost { get; set; }

Primary Key Naming

[SqlPrimaryKey("PK_CustomKey", "Id")]
public class CustomEntity
{
    public int Id { get; set; }
}

Notes

  • This package is only for backend projects.
  • It is meant to be referenced in QuickAPI but can be used in any .NET project using EF Core.
  • Supports SQL Server, PostgreSQL, and other EF Core-supported databases.

License

This project is licensed under the Apache 2.0 License.

Keywords

api

FAQs

Package last updated on 04 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts