-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
343 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-FileCopyrightText: 2025 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Package categories 提供了几种用于分类的方式 | ||
package categories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-FileCopyrightText: 2024 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Package linkages 提供简单的级联链表管理 | ||
package linkages | ||
|
||
import ( | ||
"github.com/issue9/orm/v6" | ||
|
||
"github.com/issue9/cmfx/cmfx" | ||
) | ||
|
||
func buildDB(mod *cmfx.Module, tableName string) *orm.DB { | ||
return mod.DB().New(mod.DB().TablePrefix() + "_linkages_" + tableName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2025 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package tags | ||
|
||
import ( | ||
"github.com/issue9/orm/v6" | ||
"github.com/issue9/web" | ||
|
||
"github.com/issue9/cmfx/cmfx" | ||
) | ||
|
||
// Install 安装数据库以及相关的初始数据 | ||
func Install(mod *cmfx.Module, tableName string, tag ...string) *Module { | ||
db := buildDB(mod, tableName) | ||
|
||
if err := db.Create(&TagPO{}); err != nil { | ||
panic(web.SprintError(mod.Server().Locale().Printer(), true, err)) | ||
} | ||
|
||
if len(tag) == 0 { | ||
panic("参数 tag 不能为空") | ||
} | ||
|
||
err := db.DoTransaction(func(tx *orm.Tx) error { | ||
tags := make([]orm.TableNamer, 0, len(tag)) | ||
for _, t := range tag { | ||
tags = append(tags, &TagPO{Title: t}) | ||
} | ||
return tx.InsertMany(50, tags...) | ||
}) | ||
if err != nil { | ||
panic(web.SprintError(mod.Server().Locale().Printer(), true, err)) | ||
} | ||
|
||
return Load(mod, tableName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-FileCopyrightText: 2025 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package tags | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/issue9/assert/v4" | ||
|
||
"github.com/issue9/cmfx/cmfx/initial/test" | ||
) | ||
|
||
func TestInstall(t *testing.T) { | ||
a := assert.New(t, false) | ||
s := test.NewSuite(a) | ||
defer s.Close() | ||
|
||
mod := s.NewModule("mod") | ||
|
||
a.PanicString(func() { | ||
Install(mod, "lk") | ||
}, "参数 tag 不能为空") | ||
|
||
l := Install(mod, "lk", "t1", "t2") | ||
a.NotNil(l) | ||
|
||
s.TableExists("mod_tags_lk") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-FileCopyrightText: 2025 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package tags | ||
|
||
type TagPO struct { | ||
XMLName struct{} `orm:"-" json:"-" yaml:"-" cbor:"-" xml:"tag"` | ||
|
||
ID int64 `orm:"name(id);ai" json:"id" yaml:"id" cbor:"id" xml:"id,attr"` | ||
Title string `orm:"name(title);len(20)" json:"title" yaml:"title" cbor:"title" xml:"title"` // 此标签的简要说明 | ||
} | ||
|
||
func (po *TagPO) TableName() string { return `` } |
Oops, something went wrong.