Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kklldog/AgileRepository
a repository lib like spring data jpa .
https://github.com/kklldog/AgileRepository
Last synced: 3 months ago
JSON representation
a repository lib like spring data jpa .
- Host: GitHub
- URL: https://github.com/kklldog/AgileRepository
- Owner: kklldog
- Created: 2018-01-18T09:10:19.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-07T03:00:24.000Z (almost 7 years ago)
- Last Synced: 2024-04-14T05:33:43.863Z (10 months ago)
- Language: C#
- Homepage:
- Size: 430 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AgileRepository
这是一个可以帮助你快速开发Repository的lib。有点像Springdata JPA根据方法名、注解来自动生成查询方法的功能。
对于一些简单的查询,只需要定义接口就行了,实现都不用。## 依赖
AspectCore >= 0.2.4
Dapper >= 1.50.4
DapperExtensions >= 1.6.3
System.Threading.Tasks.Extensions >= 4.3.0
## 使用
public interface IUserRepository:IAgileRepository
{
[QueryByMethodName]
IEnumerable QueryByUserName(string userName);}
var repository = AgileRepository.Proxy.SingletonInstance();
repository.QueryByUserName("admin");
## 配置
AgileRepository.SetConfig(new AgileRepositoryConfig()
{
SqlMonitor = (sql, paramters ) =>
{
Console.WriteLine(sql);
},
ConnectionName = "conn"
});
## 示例
### 根据sql查询
[QueryBySql("SELECT * FROM USERS")]
IEnumerable TestSql();[QueryBySql("SELECT * FROM USERS where username=@userName")]
IEnumerable TestSql1(string userName);
### 根据方法名称查询
[QueryByMethodName]
IEnumerable QueryByUserName(string userName);[QueryByMethodName]
IEnumerable QueryByUserNameAndId(string userName, string id);[QueryByMethodName]
IEnumerable QueryByCreaterIsNull();[QueryByMethodName]
IEnumerable QueryByCreaterIsNotNull();
### 查询所有
[QueryAll]
IEnumerable QueryAll();
### 根据 sql Count
[CountBySql("Select count(*) from users")]
int TestCount();[CountBySql("Select count(*) from users where userName=@userName")]
int TestCount1(string userName);
### 根据方法名Count
[CountByMethodName]
int CountByUserName(string userName);[CountByMethodName]
int CountByIdAndUserName(string id, string userName);
### Count所有
[CountAll]
int CountAll();
### Insert
[Insert]
int Insert(User user);
[Insert]
int Insert(IEnumerable users);
### Update
[Update]
int Update(User user);[Update]
int Update(IEnumerable users);
###
[Delete]
int Delete(User user);[Delete]
int Delete(IEnumerable users);[DeleteByMethodName]
int DeleteByUserName(string userName);
### 执行非查询sql
[ExecuteBySql("Delete from [users] where id =@id ")]
int Execute(string id);
## 支持的where关键字
Key | Name | Where
--- | ----- |-----
And | QueryByUserNameAndId | where UserName=@UserName And Id=@Id
Or | QueryByUserNameOrId | where UserName=@UserName Or Id=@Id
IsNull | QueryByUserNameIsNull | where UserName Is Null
IsNotNull | QueryByUserNameIsNotNull | where UserName Is Not Null
GreaterThen | QueryByAgeGreaterThen | where Age>@Age
GreaterEqual | QueryByAgeGreaterEqual | where Age>=@Age
LessThen | QueryByAgeLessThen | where Age<@Age
LessEqual | QueryByAgeLessEqual | where Age<=@Age
Not | QueryByAgeNot | where Age!=@Age
In | QueryByUserNameIn | where UserName in @UserName
NotIn | QueryByUserNameNotIn | where UserName Not in @UserName
Like | QueryByUserNameLike | where UserName Like @UserName
NotLike | QueryByUserNameNotLike | where UserName Not Like @UserName