Here's an improved version of your README:
CustomORM is not a full-fledged ORM but rather a collection of functions designed to generate and execute SQL queries based on specific struct definitions. It is tailored for PostgreSQL databases.
- Generate and execute SQL queries based on struct definitions
- Designed to work seamlessly with PostgreSQL databases
- Support for table creation, insertion, updating, deletion, and querying
Define your structs with tags specifying SQL constraints and properties:
typeDomainstruct {Idint64`json:"id" customsql:"pkey:id;check(id <> 0)"`Enabledbool`json:"enabled" customsql:"enabled;default=TRUE"`Namestring`json:"name" customsql:"name;unique;check(name <> '')"`}func (d*Domain)GetTableName()string {return"domains"}typeDomainUserstruct {Idint64`json:"id" customsql:"pkey:id;check(id <> 0)"`Positionint64`json:"position" customsql:"position;position"`Enabledbool`json:"enabled" customsql:"enabled;default=TRUE"`Namestring`json:"name" customsql:"name;unique_1;check(name <> '')"`Parent*Domain`json:"parent" customsql:"fkey:parent_id;unique_1;check(parent_id <> 0)"`}func (d*DomainUser)GetTableName()string {return"domain_users"}The tagsunique andindex can be grouped using an underscore, such asunique_1. To set the order within a group, add a suffix after a hyphen, for example,index_1-1 andindex_1-2.
corm:=customorm.Init(db)corm.CreateTable(&Domain{})// Returns boolcorm.CreateTable(&DomainUser{})// Returns boolcorm:=customorm.Init(db)corm.InsertRow(&DomainUser{Name:"UserName",Parent:&altStruct.Domain{Id:parentId},Enabled:true,})// Returns int64, errorcorm:=customorm.Init(db)corm.UpdateRow(&DomainUser{Id:1,Name:"NewUserName",},true,map[string]bool{"Name":true})// Returns errorcorm:=customorm.Init(db)corm.DeleteRowById(&DomainUser{Id:1})// Returns errorcorm.DeleteRowByArgId(&DomainUser{},1)// Returns errorcorm.DeleteRows(&DomainUser{Enabled:false},map[string]bool{"Enabled":true})// Returns errorcorm:=customorm.Init(db)corm.GetDataAll(&DomainUser{},true)// Returns interface{}, errorfilter:= customOrm.Filters{Fields:map[string]FilterFields{"Name": {Flag:true,// Use this filterUseValue:false,// Use value from struct or from value field belowValue:nil,// Can use this value instead of value from structOperand:"",// Operand to compare with value of (<,>,=,CONTAINS,IN) default "=" }, },Order: customOrm.Order{Desc:true,// Sort DESCFields: []string{"Id"},// Sort by field names },Limit:10,Offset:0,Count:false,// If true, returns count(*) instead of fields}corm.GetDataByValue(&DomainUser{Id:1},filter,false)// Returns interface{}, errorFeel free to adjust and expand upon these examples to suit your specific use cases.