Skip to content

Commit

Permalink
Merge pull request #7 from Kekenika/update-document
Browse files Browse the repository at this point in the history
Update document implementation
  • Loading branch information
KeisukeYamashita authored Nov 3, 2021
2 parents c8ad091 + 6f60adf commit 5265396
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
5 changes: 4 additions & 1 deletion docs/data-sources/document.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ data "typesense_document" "my_doc" {
### Required

- **collection_name** (String) Name of the collection
- **id** (String) ID of the document

### Optional

- **id** (String) The ID of this resource.

### Read-Only

Expand Down
5 changes: 4 additions & 1 deletion docs/resources/document.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ resource "typesense_document" "doc" {

- **collection_name** (String) Name of the collection
- **document** (Map of String) Document's body
- **id** (String) ID of the document

### Optional

- **id** (String) The ID of this resource.

## Import

Expand Down
5 changes: 0 additions & 5 deletions typesense/data_source_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ func dataSourceTypesenseDocument() *schema.Resource {
return &schema.Resource{
Description: "Item in a collection",
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "ID of the document",
Required: true,
},
"collection_name": {
Type: schema.TypeString,
Description: "Name of the collection",
Expand Down
11 changes: 3 additions & 8 deletions typesense/resource_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ func resourceTypesenseDocument() *schema.Resource {
return &schema.Resource{
Description: "Item in a collection",
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "ID of the document",
Required: true,
},
"collection_name": {
Type: schema.TypeString,
Description: "Name of the collection",
Expand Down Expand Up @@ -61,12 +56,12 @@ func resourceTypesenseDocumentUpsert(ctx context.Context, d *schema.ResourceData
}

var id string
if v, ok := d.GetOk("id"); ok {
if v, ok := document["id"]; ok {
id = v.(string)
} else {
return diag.Errorf("id required for document")
}

document["id"] = id

_, err := client.Collection(collectionName).Documents().Create(document)
if err != nil {
return diag.FromErr(err)
Expand Down

0 comments on commit 5265396

Please sign in to comment.