| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
nORM is a lightweight, simple, and fast Object-Relational Mapping (ORM) library for .NET applications. It provides an easy way to interact with different database systems without the complexity of larger ORM frameworks.
Note: This README is AI-generated and updated as the project evolves. It aims to keep documentation in sync with the rapidly changing codebase and emerging ideas during active development.
Will be available on NuGet soon, once it is fully tested and documented. For now, you can clone the repository and build the project to get the library. You can also add the project as a submodule to your existing project.
using nORM.Attributes;
using nORM.Models;
[CollectionName("Posts")]
public class Post : NormEntity
{
[PrimaryKey]
[Column("id")]
public int Id { get; set; }
[Column("title")]
public string Title { get; set; }
[Column("description")]
public string Description { get; set; }
[Column("author_id")]
public int AuthorId { get; set; }
[Column("created_at")]
public DateTime CreatedAt { get; set; }
}// For SQLite
var sqliteConnection = new NormConnectionBuilder(DatabaseProviderType.Sqlite)
.SetExplicitDataSource("database.sqlite")
.BuildAndConnect();
// For MySQL
var mysqlConnection = new NormConnectionBuilder(DatabaseProviderType.MySql)
.SetHostname("localhost")
.SetUsername("username")
.SetPassword("password")
.SetDatabase("mydatabase")
.BuildAndConnect();
// For in-memory SQLite
var inMemoryConnection = new NormConnectionBuilder(DatabaseProviderType.Sqlite)
.UseInMemoryDataSource()
.BuildAndConnect();// Get a collection context
var postCollection = connection.Collection<Post>();
// Insert a new record
var post = new Post
{
Title = "Hello nORM",
Description = "My first post with nORM",
AuthorId = 1,
CreatedAt = DateTime.UtcNow
};
var insertedPost = postCollection.Insert(post);
// Find a post by ID
var fetchedPost = postCollection.FindOne(p => p.Id == insertedPost.Id);
// Remove a post
var result = postCollection.Remove(fetchedPost);
// Using transactions
using (var transaction = postCollection.BeginTransaction())
{
try
{
// Perform multiple operations
postCollection.Insert(post1, transaction);
postCollection.Insert(post2, transaction);
// Commit when done
transaction.Commit();
}
catch
{
// Transaction will be automatically rolled back if not committed
}
}// Insert multiple entities
var posts = new List<Post> { post1, post2, post3 };
var insertedPosts = postCollection.InsertMany(posts);
// Truncate a table
var truncated = postCollection.Truncate();nORM is designed to be lightweight and efficient. The library includes features to minimize memory allocations and GC pressure:
When working with large datasets, consider using transactions for bulk operations to improve performance.
The following .NET types are currently supported:
nORM is designed with a provider-agnostic architecture that will allow for easy integration with various database technologies while maintaining strong static typing:
The provider architecture allows you to seamlessly switch between different databases without changing your application code, making it easy to transition between development, testing, and production environments with different database backends.
// Example of provider swapping (current implementation)
// SQLite for development
var devConnection = new NormConnectionBuilder(DatabaseProviderType.Sqlite)
.UseInMemoryDataSource()
.BuildAndConnect();
// MySQL for production
var prodConnection = new NormConnectionBuilder(DatabaseProviderType.MySql)
.SetHostname("production-server")
.SetUsername("prod-user")
.SetPassword("secure-password")
.SetDatabase("production-db")
.BuildAndConnect();
// Future NoSQL support (maintaining static typing)
// var mongoConnection = new NormConnectionBuilder(DatabaseProviderType.MongoDB)
// .SetConnectionString("mongodb://localhost:27017")
// .SetDatabase("my-documents")
// .BuildAndConnect();
//
// // Still use your statically typed entity classes
// var postsCollection = mongoConnection.Collection<Post>();nORM is currently in active development. Future plans include:
This project is licensed under a custom license that allows free use, modification, and distribution but restricts selling the software as a standalone product. See the LICENSE file for details.
| Back | FazBrowse Home | New Git URL |