通常我将 Web 项目分成多个域,每个域都有一个服务(业务层)和存储库(数据访问层)。我正在创建一个项目,其中有两个域(作业和标题)。
创建或更新作业时,标题最终也会更新。该流程由作业/服务编排,作业/服务在内部调用标头/服务。当发生多个插入/更新时,使用事务来控制该过程。
通常,在 Go 中创建事务时,会返回一个“Tx”实例,并应在进一步的查询中使用,直到提交为止。唯一的问题是数据库是在存储库创建时注入的,以后无法更改,因为多个请求将通过引用使用同一存储库。在这种情况下有哪些选择?
我想到的唯一选择是将数据库作为存储库方法的参数传递。
pkg/存储/database.go
package storage
import (
"chronos/pkg/errors"
"github.com/jinzhu/gorm"
)
// DB Database storage interface
type DB interface {
Add(interface{}) error
Delete(interface{}) error
Begin() (DB, error)
Rollback() (DB, error)
Commit() (DB, error)
}
// Gorm Database implementation using GORM
type Gorm struct {
*gorm.DB
SQL *gorm.DB
}
// NewGorm Return new gorm storage instance
func NewGorm(db *gorm.DB) *Gorm {
db = db.
Set("gorm:association_autocreate", false).
Set("gorm:association_autoupdate", false).
Set("gorm:save_associations", false).
Set("gorm:association_save_reference", false)
return &Gorm{db, db}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个系统,该系统具有将个人资料图片上传到其他网络的工具.Twitter有一个API点,Facebook有一些"技巧",但我的问题是:有一种方法可以在谷歌+上做到这一点?
我检查了API(https://developers.google.com/+/api/latest/)并没有找到任何内容,但在Facebook上,我可以将图片发布到特定的相册,然后发送给用户到窗口重新定义配置文件图片.在Google+中我也有这个选项吗?在这种情况下我还能做些什么?
我找到了一些较旧的版本,允许在Google Apps个人资料中上传新图片(https://developers.google.com/google-apps/profiles/#Updating).也许这是路径,但据我所知,Google+是新的Google个人资料= \
我正在尝试安装SailsJS:
$ sudo npm install -g sails
Run Code Online (Sandbox Code Playgroud)
它可以使用以下日志在/ home/brunoluiz/npm/lib/node_modules/sails中安装所有内容:
/home/brunoluiz/npm/bin/sails -> /home/brunoluiz/npm/lib/node_modules/sails/bin/sails.js
sails@0.9.16 /home/brunoluiz/npm/lib/node_modules/sails
??? connect-flash@0.1.1
??? pluralize@0.0.5
??? inflection@1.2.5
??? grunt-sails-linker@0.9.5
??? grunt-contrib-clean@0.4.1
??? node-uuid@1.4.0
??? async@0.2.9
??? grunt-contrib-concat@0.3.0
??? grunt-contrib-copy@0.4.1
??? grunt-contrib-coffee@0.7.0
??? ejs-locals@1.0.2
??? ejs@0.8.4
??? underscore.string@2.3.0
??? coffee-script@1.6.2
??? lodash@2.4.1
??? i18n@0.4.1 (debug@0.8.0, sprintf@0.1.3)
??? optimist@0.3.4 (wordwrap@0.0.2)
??? include-all@0.1.2 (underscore.string@2.3.1)
??? sails-disk@0.9.3 (waterline-criteria@0.9.7, lodash@2.3.0, fs-extra@0.8.1)
??? fs-extra@0.5.0 (jsonfile@0.0.1, ncp@0.2.7, mkdirp@0.3.5, rimraf@2.1.4)
??? connect-redis@1.4.5 (debug@0.8.0, redis@0.7.3)
??? grunt-contrib-jst@0.5.0 (lodash@1.0.1, grunt-lib-contrib@0.5.3)
??? glob@3.1.14 (inherits@1.0.0, graceful-fs@1.1.14, minimatch@0.2.14)
??? grunt-contrib-cssmin@0.6.1 …Run Code Online (Sandbox Code Playgroud)