Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couch.Doc interface #37

Merged
merged 8 commits into from
Oct 10, 2016
Merged

couch.Doc interface #37

merged 8 commits into from
Oct 10, 2016

Conversation

jinroh
Copy link
Contributor

@jinroh jinroh commented Oct 10, 2016

See #36.

The doctype on the JSONDoc felt weird and we may fallback on this one... This change will affect the crud api since it adds a explicit doctype field to documents.. while the _id field also contains it. I'm not really sure about that.

Other than that, I don't see many issue.

if err := c.BindJSON(&doc); err != nil {
c.AbortWithError(http.StatusBadRequest, err)
return
}

err := couchdb.CreateDoc(prefix, doctype, doc)
doc["doctype"] = doctype
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😕

@nono
Copy link
Member

nono commented Oct 10, 2016

What can we do to avoid the doctype in the JSON?

One possibility is to add a ToJSON() method to our interface and modify JSONDoc to:

type JSONDoc struct {
  DocType string
  Data map[string]interface{}
}

@aenario
Copy link
Contributor

aenario commented Oct 10, 2016

How about

type JSONDoc map[string]interface{}
func (d *JSONDoc) Doctype {
id, ok = d["_id"].(string)
if !ok || id=="" { 
    return ""
}
return id[0:strings.Index(id, "/")]
}

?

@nono
Copy link
Member

nono commented Oct 10, 2016

@aenario and how do you create a new document? You create the id in go, and not on relying on couchdb?

@aenario
Copy link
Contributor

aenario commented Oct 10, 2016

Yep, i did not think this in depth...

Alternatively, we can keep the doctype outside of the structure itself, then we can imagine having two APIs :

  1. The full-of-string one for /data API (with Create(prefix, doctype, doc))
  2. The go clean one :
type File 
//... 
files = couchdb.Doctype(File.Doctype())
//...
func upload()...{
    files.Create(myFile)
}

// JSONDoc is a map representing a simple json object that implements
// the Doc interface.
type JSONDoc struct {
Type string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Type is exported since there is DocType() ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to specify the type when creating a document that we will save.

@jinroh
Copy link
Contributor Author

jinroh commented Oct 10, 2016

I want to keep this PR simple for now. We can still discuss a change of API or adding the notion of serialization/deserialization later on.

Tell me if its good to merge for you (I'll remove the revert commits).

@aenario aenario merged commit 1c40680 into cozy:master Oct 10, 2016
@jinroh jinroh deleted the couch-doc-interface branch October 10, 2016 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants