From bfdd694ad225236ace0a82a231cfe89c304b3c0a Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 8 Mar 2022 16:06:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=A4=9A=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/dataset.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/models/dataset.go b/models/dataset.go index 096ab291c..e5b252ce6 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -101,11 +101,28 @@ type SearchDatasetOptions struct { } func CreateDataset(dataset *Dataset) (err error) { - if _, err = x.Insert(dataset); err != nil { + + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { return err } - return nil + datasetByRepoId := &Dataset{RepoID: dataset.RepoID} + has, err := sess.Get(datasetByRepoId) + if err != nil { + return err + } + if has { + return fmt.Errorf("The dataset already exists.") + } + + if _, err = sess.Insert(dataset); err != nil { + return err + } + return sess.Commit() + } func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) {