Meadow.Framework
1.2.3
See the version list below for details.
dotnet add package Meadow.Framework --version 1.2.3
NuGet\Install-Package Meadow.Framework -Version 1.2.3
<PackageReference Include="Meadow.Framework" Version="1.2.3" />
<PackageVersion Include="Meadow.Framework" Version="1.2.3" />
<PackageReference Include="Meadow.Framework" />
paket add Meadow.Framework --version 1.2.3
#r "nuget: Meadow.Framework, 1.2.3"
#:package Meadow.Framework@1.2.3
#addin nuget:?package=Meadow.Framework&version=1.2.3
#tool nuget:?package=Meadow.Framework&version=1.2.3
Meadow
M<nothing>anaged/<nothing>E<nothing>nhanced<nothing>Ado<nothing>W<nothing>rapper
This library is designed to help using ado.net easier and with some good practices consistently.
Features
- It Supports MS-SqlServer, My Sql, SQLite and Postgre database frameworks.
- The application would create/buildup and update database by itself after deployments.
- Your data access logic will be fully implemented in SQL language, therefore:
- You would have access to what ever feature your database framework provides with no limitations.
- Non of your data-access business would be transported to server as pure sql text
- Like Migrations in EntityFramework, each change in the database would be maintained as the project source code.
- There will be no object-tracing and each data-access operation closes the connection which helps reducing the chance of concurrency and improves performance in load peaks.
- The conversion of data to/from POCOs are internally covered so working with data is easy.
The Practice
Meadow is designed to help implementing a practice as follows:
- Design and Maintain the database, step by step, by creating build-up scripts (They would be treated like source code)
- For each data access operation, Create a Stored Procedure in a build-up script.
- For each data access operation, drive a well named request class, from
MeadowRequest
class. - Perform the request and receive the results (if any) whenever needed, using
MeadowEngine
and an instance of corresponding request.
The MeadowEngine
can take some configurations. It also performs some useful operations
for you like creating/deleting and building up the database.
- NOTE: The best practice would be to use Meadow behind your Repository Pattern implementation.
In summery
- You would use meadow for retrieving/manipulating data through the MeadowRequests
- You would use meadow for creation/deletion or building up your database (usually at the startup section of the application) via
MeadowEngine
How to Use
- Prepare your connection string, regarding your database-framework of choice. (Ms-Sql-server, MySql, SQLite)
- Setup "Build-up scripts"
- Add Meadow library to your project. (You can install the NuGet package)
- Create a MeadowRequest and it's required models To use each of your procedures in your c# code.
- Use meadow!
Build-up Scripts
Create a directory in your source codes for your build-up scripts. Directory name does not matter. Make sure this directory will be copied alongside your binaries when you build/publish your project.
ex: your-project.csproj
<ItemGroup>
<Content Include="Scripts\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
For each set of changes during the process of evolving your database, Create a script inside the build-up scripts directory. It's best to create script files, regarding you data structure changes, and in a way that i's easy to read and find where to look for scripts related to a specific part of the data base. It this sense, it would be similar to migrations in ORMs. Also try to avoid manipulating last scripts, and always create new scripts for manipulation of already existing db-objects.
- ⚠️ NOTE: MANIPULATING PREVIOUSLY ADDED SCRIPTS, WOULD REQUIRE THE DATABASE TO BE RE-CREATED WHICH IS A BIG COST FOR PRODUCTION, VERSA KEEPING THE CHANGES IN A ALWAYS FORWARDING MANNER MAKES IT SMOOTHER AND SAFER FOR PRODUCT UPDATE WITHOUT DOWN-TIME.
Each build-up script file should has .sql extension and Start with 4 digit number. The numbers would represent the files order. smaller numbers will be applied before larger numbers. (ie.: 0000_initial-database.sql or 0001-AddUserInformationTables.sql)
Add Meadow library
Meadow libraries are available on Nuget. To use meadow, you would add
Add Meadow.Framework.
PackageReference <PackageReference Include="Meadow.Framework" Version="1.0.1" />
PackageManager Install-Package Meadow.Framework -Version 1.0.1
Dotnet CLI dotnet add package Meadow.Framework --version 1.0.1
Add Meadow.<Db-Framework>. For each database-framework supported by Meadow, you would add it's own db-framework adapter:
-
PackageReference <PackageReference Include="Meadow.SqlServer" Version="1.0.0" />
PackageManager dotnet add package Meadow.SqlServer --version 1.0.0
Dotnet CLI dotnet add package Meadow.SqlServer --version 1.0.0
-
PackageReference <PackageReference Include="Meadow.SQLite" Version="1.0.0" />
PackageManager Install-Package Meadow.SQLite -Version 1.0.0
Dotnet CLI dotnet add package Meadow.SQLite --version 1.0.0
-
PackageReference <PackageReference Include="Meadow.MySql" Version="1.0.0" />
PackageManager Install-Package Meadow.MySql -Version 1.0.0
Dotnet CLI dotnet add package Meadow.MySql --version 1.0.0
-
Postgre Related Considerations Postgre Readme PackageReference <PackageReference Include="Meadow.Postgre" Version="1.0.0" />
PackageManager Install-Package Meadow.Postgre -Version 1.0.0
Dotnet CLI dotnet add package Meadow.Postgre --version 1.0.0
-
- ⚠️ NOTE: VERSIONS APPEARING IN THIS SECTION ARE NOT NECESSARILY LATEST. PLEASE CHECK OUT THE NUGET PAGE FOR EACH TO SEE THE LATEST VERSION
Creating MeadowRequests
For creating a request, you can drive from MeadowRequest
class. Its a better practice to keep your request classes under a grouped and managed
directory/namespace. You can use Conventions to write minimum code.
By Convention, a MeadowRequest named AbcRequest
, would be resolved for to execute a procedure named: spAbc
.
If you prefer not to rely on conventions, you can provide procedure name manually by overriding the the property RequestText
in your meadow request.
Meadow also contains several pre-built requests for common operations that you can drive from:
InsertSpRequest<TModel>
Inserts an Entity Of type TModel, Into the database. It expects the corresponding procedure (which you would write in build-up scripts) to (a) have one input parameter corresponding to each effectively-primitive [^1] property of TModel. (Except for the Id Parameter)
(b) return newly inserted model.UpdateSpRequest<TModel>
Updates an Entity Of Type TEntity then returns the updated value. Therefore it also
expects your stored-procedure, to (a) have one input parameter corresponding to each effectively-primitive property of TModel. (Except for the Id Parameter)
(b) return newly inserted model.ReadAllSpRequest<TModel>
Reads all records of type TModel. If you pass 'True' for the constructor argument: fullTree, then this request expects your procedure to return all fields from all other tables (joined), so it can glue all together and construct an instance of TModel and all it's properties. If you pass 'False' for full-tree argument, then a simple procedure likeselect * from <table-name> ...
would be all it needs.ReadByIdSpRequest<TModel, TId>
Reads the Entity identified by the given Id. This Request and it's descendants, would have an Id property of type:TId
. You can set this property before performing the request. This request, expects its Corresponding procedure to have one argument named after the Identity Field of your Model. the full-tree argument in this request is the same as ReadAllSpRequest.DeleteByIdSpRequest<TModel,TId>
This request is for deleting a record by its Id. Like ReadById, It uses the Id property. It returns the success result of the deletion asDeletionResult
. So it expects your procedure to return a true/false value with the field-name of Success.ByIdRequestBase
This request is the base class forReadByIdSpRequest
andDeleteByIdSpRequest
. It can be used for creating any other ById operations of interest.SaveSpRequest<TModel>
This Request to have a data inserted when it's not present in the database, and updated if it's already there. The expected input parameters are the same as Insert or Update. Also no matter the insertion happened or an update took place, the procedure should return the inserted/updated model. More On Requests
Output/Input
When you drive MeadowRequest<TIn,TOut>
, TIn would be the type of the data you send towards the database when you perform that request.
in example when you are inserting a data. The same way, TOut would be the type of data returned from the database. In a case that you do not
send any data towards the database, you should use the type MeadowVoid
for TIn. Also for those requests that would not return any data,
you will use this class.
Constructor
Another point to consider is MeadowRequest
's Constructor. It takes a boolean argument to determine if this request is obligated to read returned data.
Name Conventions
In a case that you needed to know, what Db Object Names Meadow would prefer to be used for a specific Entity,
you can instantiate NameConvention<TEntity>
class. This class will provide predefined names for common
procedures and tables regarding given type (TEntity).
Using Meadow In Your Project
Create and configure MeadowEngine
by passing a MeadowConfiguration
object to its constructor. A MeadowConfiguration object has a ConnectionString property and a BuildupScriptDirectory property which is where you save build-up scripts.
Then all you need to do is to instantiate an object of your meadow request, and call MeadowEngine.PerformRequest(request)
. Meadow creates and disposes resources per request, therefore it's not
necessary to keep the engine object. You can keep the engine object or instantiate it per request.
You can also instantiate the MeadowEngine
also by passing an object of Type IMeadowConfigurationProvider
. This would be helpful when you want to use different configurations controlled by your DI.
Examples
Meadow can be used to connect to Ms-SqlServer, My-Sql, SQLite and Postgre. For each of these databases, these is an examples in the project. You can see that using Meadow is the same in each example, but the only difference is in the actual sql scripts written for each database.
ℹ️ NOTE: SQLITE, DOES NOT SUPPORT STORED PROCEDURES, AND MEADOW IS BASED ON STORED PROCEDURES. SO MEADOW DOES STORE YOUR PROCEDURES SEAMLESSLY.
When The Darkness Caresses The Meadows...[^2] (Bugs and Issues)
Meadow For Ms-SqlServer is currently being tested in my other projects, but for MySql, SQLite and Postgre, It still has not being tested in practice. So Please consider dropping a mail or comment or opening a github issue if you faced a bug or an issue. Very Thanks.
Developing a new Database system Adapter
Meadow can recognize any database system through it's abstractions. The main enttry for
any database system is the interface IMeadowDataAccessCoreProvider
which connects your database
system for the meadow engine and can make use of it in higher levels of your code seamlessly.
IMeadowDataAccessCoreProvider
provides your implementation of IMeadowDataAccessCore
. This interface
defines a database system via several functions to be implemented. The Main method to be implemented, would be
IMeadowSataAccessCore.Perform<.>(.)
. Other methods are for creating and also providing the
basic functionalities meadow needs for it's internal buildup process.
In most cases, you might not need to implement IMeadowDataAccessCore
from scratch. Instead, you can
extend the MeadowDataAccessCoreBase
class. This class handles a portion of implementation
and breaks down the remaining into the implementation of:
IStandardDataStorageAdapter
IStorageCommunication
You still do not have to implement IStandardDataStorageAdapter
from the scratch in all cases. For sql database systems,
you can extend SqlDataStorageAdapterBase
.
Easier Implementation For Ado wrapped database systems
If The database system of your interest, does already have an ADO implementation, you can write your adapter,
just by extending the class AdoDataAccessCoreBase
. and implement its methods. You also would have to provide
an implementation of IDbTypeNameMapper
which is a dictionary, mapping the c# System types to proper data types
known in your database system.
Contact
Please feel free to contact me about meadow, or any related questions.
acidmanic.moayedi@gmail.com
https://www.linkedin.com/in/mani-moayedi
https://www.instagram.com/acidmanix/
Thanks And Regards. Mani.
.
[^1]: For Meadow, Effectively Primitive mean any type that is able to be inserted directly into the database. It involves all primitives, plus the String, DateTime and etc.... [^2]: IGNEA, Jahi.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Acidmanic.Utilities (>= 1.0.0)
- Acidmanic.Utilities.Reflections (>= 1.0.5)
- Newtonsoft.Json (>= 13.0.1)
- System.Data.SqlClient (>= 4.8.3)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Meadow.Framework:
Package | Downloads |
---|---|
EnTier.DataAccess.Meadow
This package adds extensions to use Meadow with EnTier |
|
Meadow.MySql
Meadow MySql Adapter |
|
Meadow.SqlServer
Meadow SqlServer Adapter |
|
Meadow.SQLite
Meadow SQLite Adapter |
|
Meadow.Postgre
Meadow Postgre Adapter |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.2.4-b54 | 160 | 8/9/2024 |
1.2.4-b53 | 136 | 8/8/2024 |
1.2.4-b52 | 113 | 7/18/2024 |
1.2.4-b51 | 111 | 7/17/2024 |
1.2.4-b50 | 92 | 7/15/2024 |
1.2.4-b49 | 134 | 7/10/2024 |
1.2.4-b48 | 95 | 7/10/2024 |
1.2.4-b47 | 168 | 7/7/2024 |
1.2.4-b46 | 187 | 7/5/2024 |
1.2.4-b45 | 177 | 7/4/2024 |
1.2.4-b44 | 152 | 7/4/2024 |
1.2.4-b43 | 142 | 3/15/2024 |
1.2.4-b42 | 149 | 2/25/2024 |
1.2.4-b41 | 154 | 2/25/2024 |
1.2.4-b40 | 126 | 2/25/2024 |
1.2.4-b39 | 322 | 10/28/2023 |
1.2.4-b38 | 141 | 10/28/2023 |
1.2.4-b37 | 136 | 10/28/2023 |
1.2.4-b36 | 205 | 10/21/2023 |
1.2.4-b35 | 222 | 10/21/2023 |
1.2.4-b34 | 218 | 10/4/2023 |
1.2.4-b33 | 232 | 9/15/2023 |
1.2.4-b32 | 222 | 9/15/2023 |
1.2.4-b31 | 194 | 9/14/2023 |
1.2.4-b30 | 183 | 9/14/2023 |
1.2.4-b29 | 174 | 9/14/2023 |
1.2.4-b28 | 184 | 9/12/2023 |
1.2.4-b26 | 211 | 9/12/2023 |
1.2.4-b25 | 223 | 9/7/2023 |
1.2.4-b24 | 131 | 9/6/2023 |
1.2.4-b23 | 184 | 9/6/2023 |
1.2.4-b22 | 195 | 9/3/2023 |
1.2.4-b21 | 193 | 9/2/2023 |
1.2.4-b20 | 178 | 9/2/2023 |
1.2.4-b19 | 209 | 8/31/2023 |
1.2.4-b18 | 174 | 8/31/2023 |
1.2.4-b17 | 177 | 8/30/2023 |
1.2.4-b16 | 179 | 8/30/2023 |
1.2.4-b15 | 151 | 8/29/2023 |
1.2.4-b14 | 227 | 8/29/2023 |
1.2.4-b13 | 199 | 8/28/2023 |
1.2.4-b12 | 186 | 8/26/2023 |
1.2.4-b11 | 188 | 8/26/2023 |
1.2.4-b10 | 194 | 6/16/2023 |
1.2.4-b09 | 257 | 3/16/2023 |
1.2.4-b08 | 289 | 3/7/2023 |
1.2.4-b07 | 240 | 3/6/2023 |
1.2.4-b06 | 345 | 2/26/2023 |
1.2.4-b05 | 313 | 2/20/2023 |
1.2.4-b02 | 250 | 1/17/2023 |
1.2.4-b01 | 180 | 12/28/2022 |
1.2.3 | 761 | 11/2/2022 |
1.2.2 | 465 | 10/4/2022 |
1.1.8 | 484 | 9/24/2022 |
1.1.7 | 754 | 9/9/2022 |
1.1.6 | 1,224 | 9/6/2022 |
1.1.5 | 943 | 9/5/2022 |
1.1.4 | 728 | 9/4/2022 |
1.1.3 | 449 | 9/4/2022 |
1.1.2 | 1,227 | 9/3/2022 |
1.1.1 | 961 | 8/31/2022 |
1.1.0 | 1,205 | 8/28/2022 |
1.0.6 | 435 | 8/25/2022 |
1.0.5 | 738 | 8/21/2022 |
1.0.4 | 740 | 8/16/2022 |
1.0.3 | 1,473 | 8/15/2022 |
1.0.2 | 466 | 8/15/2022 |
1.0.1 | 1,258 | 8/9/2022 |
1.0.0 | 726 | 6/28/2022 |