Compare commits
4 Commits
v1.0.0
...
4a5ecc647d
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a5ecc647d | |||
| be5e8b6140 | |||
| c1b1d2d5f1 | |||
| 17047d2c71 |
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Georgiy Derbenev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
12
go.mod
12
go.mod
@@ -1,12 +1,14 @@
|
||||
module git.gogacoder.ru/NTO/crudgen
|
||||
|
||||
go 1.22.12
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.24.1
|
||||
|
||||
require github.com/dave/dst v0.27.3
|
||||
|
||||
require (
|
||||
golang.org/x/mod v0.23.0 // indirect
|
||||
golang.org/x/sync v0.11.0 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/tools v0.13.0 // indirect
|
||||
golang.org/x/mod v0.24.0 // indirect
|
||||
golang.org/x/sync v0.12.0 // indirect
|
||||
golang.org/x/sys v0.31.0 // indirect
|
||||
golang.org/x/tools v0.31.0 // indirect
|
||||
)
|
||||
|
||||
7
go.sum
7
go.sum
@@ -8,11 +8,18 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
|
||||
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
|
||||
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
||||
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
|
||||
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
|
||||
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
|
||||
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package internal
|
||||
|
||||
const CreateRawTemplate = `func (service *{{.ServiceName}}) Create(item {{.EntityType}}) ({{.EntityType}}, error) {
|
||||
err := dal.{{.EntityType}}.Preload(field.Associations).Create(&item)
|
||||
utils.ReplaceEmptySlicesWithNil(&item)
|
||||
err := dal.Author.Create(&item)
|
||||
if err != nil {
|
||||
return item, err
|
||||
}
|
||||
err = utils.AppendAssociations(database.GetInstance(), &item)
|
||||
return item, err
|
||||
}`
|
||||
|
||||
@@ -24,13 +29,25 @@ const GetByIdRawTemplate = `func (service *{{.ServiceName}}) GetById(id uint) (*
|
||||
}`
|
||||
|
||||
const UpdateRawTemplate = `func (service *{{.ServiceName}}) Update(item {{.EntityType}}) ({{.EntityType}}, error) {
|
||||
err := dal.{{.EntityType}}.Preload(field.Associations).Save(&item)
|
||||
utils.ReplaceEmptySlicesWithNil(&item)
|
||||
|
||||
_, err := dal.Author.Updates(&item)
|
||||
if err != nil {
|
||||
return item, err
|
||||
}
|
||||
|
||||
err = utils.UpdateAssociations(database.GetInstance(), &item)
|
||||
|
||||
if err != nil {
|
||||
return item, err
|
||||
}
|
||||
|
||||
return item, err
|
||||
}`
|
||||
|
||||
const DeleteRawTemplate = `func (service *{{.ServiceName}}) Delete(item {{.EntityType}}) ({{.EntityType}}, error) {
|
||||
_, err := dal.{{.EntityType}}.Unscoped().Preload(field.Associations).Delete(&item)
|
||||
return item, err
|
||||
const DeleteRawTemplate = `func (service *{{.ServiceName}}) Delete(id uint) error {
|
||||
_, err := dal.{{.EntityType}}.Unscoped().Where(dal.{{.EntityType}}.Id.Eq(id)).Delete()
|
||||
return err
|
||||
}`
|
||||
|
||||
const CountRawTemplate = `func (service *{{.ServiceName}}) Count() (int64, error) {
|
||||
|
||||
@@ -8,7 +8,9 @@ type CrudTemplatesContext struct {
|
||||
|
||||
var ServiceImports = []string{
|
||||
"app/internal/dal",
|
||||
"app/internal/database",
|
||||
"app/internal/models",
|
||||
"app/internal/utils",
|
||||
"errors",
|
||||
"gorm.io/gen/field",
|
||||
"gorm.io/gorm",
|
||||
|
||||
Reference in New Issue
Block a user