Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SQL generator based on structures tags

License

NotificationsYou must be signed in to change notification settings

custompbx/customorm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Features

  • 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

Usage

Struct Definitions

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.

Creating Tables

corm:=customorm.Init(db)corm.CreateTable(&Domain{})// Returns boolcorm.CreateTable(&DomainUser{})// Returns bool

Inserting Rows

corm:=customorm.Init(db)corm.InsertRow(&DomainUser{Name:"UserName",Parent:&altStruct.Domain{Id:parentId},Enabled:true,})// Returns int64, error

Updating Rows

corm:=customorm.Init(db)corm.UpdateRow(&DomainUser{Id:1,Name:"NewUserName",},true,map[string]bool{"Name":true})// Returns error

Deleting Rows

corm:=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 error

Querying Rows

corm:=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{}, error

Feel free to adjust and expand upon these examples to suit your specific use cases.

About

SQL generator based on structures tags

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp