mirror of
https://github.com/documize/community.git
synced 2025-07-24 07:39:43 +02:00
[WIP] new schema implementation
This commit is contained in:
parent
9c2594b1b4
commit
28342fcf5e
27 changed files with 1413 additions and 1158 deletions
|
@ -15,12 +15,11 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store/mysql"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/model/attachment"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Scope provides data access to MySQL.
|
||||
|
@ -36,7 +35,7 @@ func (s Scope) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
|
|||
bits := strings.Split(a.Filename, ".")
|
||||
a.Extension = bits[len(bits)-1]
|
||||
|
||||
_, err = ctx.Transaction.Exec("INSERT INTO attachment (refid, orgid, documentid, job, fileid, filename, data, extension, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_doc_attachment (c_refid, c_orgid, c_documentid, c_job, c_fileid, c_filename, c_data, c_extension, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
a.RefID, a.OrgID, a.DocumentID, a.Job, a.FileID, a.Filename, a.Data, a.Extension, a.Created, a.Revised)
|
||||
|
||||
if err != nil {
|
||||
|
@ -48,7 +47,13 @@ func (s Scope) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
|
|||
|
||||
// GetAttachment returns the database attachment record specified by the parameters.
|
||||
func (s Scope) GetAttachment(ctx domain.RequestContext, orgID, attachmentID string) (a attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Get(&a, "SELECT id, refid, orgid, documentid, job, fileid, filename, data, extension, created, revised FROM attachment WHERE orgid=? and refid=?",
|
||||
err = s.Runtime.Db.Get(&a, `
|
||||
SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
|
||||
c_filename AS filename, c_data AS data, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
WHERE c_orgid=? and c_refid=?`,
|
||||
orgID, attachmentID)
|
||||
|
||||
if err != nil {
|
||||
|
@ -60,7 +65,15 @@ func (s Scope) GetAttachment(ctx domain.RequestContext, orgID, attachmentID stri
|
|||
|
||||
// GetAttachments returns a slice containing the attachement records (excluding their data) for document docID, ordered by filename.
|
||||
func (s Scope) GetAttachments(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Select(&a, "SELECT id, refid, orgid, documentid, job, fileid, filename, extension, created, revised FROM attachment WHERE orgid=? and documentid=? order by filename", ctx.OrgID, docID)
|
||||
err = s.Runtime.Db.Select(&a, `
|
||||
SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
|
||||
c_filename AS filename, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
WHERE c_orgid=? and c_docid=?
|
||||
ORDER BY c_filename`,
|
||||
ctx.OrgID, docID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute select attachments")
|
||||
|
@ -71,7 +84,15 @@ func (s Scope) GetAttachments(ctx domain.RequestContext, docID string) (a []atta
|
|||
|
||||
// GetAttachmentsWithData returns a slice containing the attachement records (including their data) for document docID, ordered by filename.
|
||||
func (s Scope) GetAttachmentsWithData(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Select(&a, "SELECT id, refid, orgid, documentid, job, fileid, filename, extension, data, created, revised FROM attachment WHERE orgid=? and documentid=? order by filename", ctx.OrgID, docID)
|
||||
err = s.Runtime.Db.Select(&a, `
|
||||
SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
|
||||
c_filename AS filename, c_data AS data, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
WHERE c_orgid=? and c_docid=?
|
||||
ORDER BY c_filename`,
|
||||
ctx.OrgID, docID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute select attachments with data")
|
||||
|
@ -83,5 +104,5 @@ func (s Scope) GetAttachmentsWithData(ctx domain.RequestContext, docID string) (
|
|||
// Delete deletes the id record from the database attachment table.
|
||||
func (s Scope) Delete(ctx domain.RequestContext, id string) (rows int64, err error) {
|
||||
b := mysql.BaseQuery{}
|
||||
return b.DeleteConstrained(ctx.Transaction, "attachment", ctx.OrgID, id)
|
||||
return b.DeleteConstrained(ctx.Transaction, "dmz_doc_attachment", ctx.OrgID, id)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue