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

[Design and Development] Data Fields as Primary Key/Identifier in-place of _id #111

Closed
TanmoySG opened this issue Apr 29, 2023 · 0 comments · Fixed by #137
Closed

[Design and Development] Data Fields as Primary Key/Identifier in-place of _id #111

TanmoySG opened this issue Apr 29, 2023 · 0 comments · Fixed by #137
Assignees
Labels
enhancement New feature or request

Comments

@TanmoySG
Copy link
Owner

Currently, _id is generated and used as primary identifier for a data-row(?). For example, now for data inserted , the Primary ID

{
  "name" : "T",
  "student_id" : 0123,
  "age": 21
}

the Identifier is random generated identifier _id,

{
  "axo0193nc4101383" : {"name" : "T", "student_id" : 0123, "age": 21},
}

For advanced use-cases, user might want to use any of the field values as identifier instead of _id. Eg instead of _id we want to use student_id as primary key.

{
  "0123" : {"name" : "T", "student_id" : 0123, "age": 21},
}

Possible solutions

  • Adding a field IdentifierField (string) in the Datum struct

    wunderDB/model/models.go

    Lines 42 to 46 in e7b8cdd

    type Datum struct {
    Data interface{} `json:"data"`
    Metadata Metadata `json:"metadata"`
    Identifier Identifier `json:"id"`
    }
  • When creating a collection, in addition to schema pass the identifier
{
    "name": "test-metadata1",
    "schema": {"type": "object", "properties": {"name": {"type": "string"}},"required": ["name"]},
    "identifier" : "name"
}
  • In code, check if identifier value is in the required array of the schema - request valid only if it is there or if not there can add through code.
  • While inserting data, check if identifier field is _id or any other custom field,
    • check if the identifier field is in the data, if not reject
    • if there, check if value already exists data[identifier.value] if not insert the data
@TanmoySG TanmoySG self-assigned this Jul 29, 2023
@TanmoySG TanmoySG added the enhancement New feature or request label Jul 29, 2023
@TanmoySG TanmoySG mentioned this issue Aug 6, 2023
1 task
TanmoySG added a commit that referenced this issue Aug 6, 2023
Merge pull request #137 from TanmoySG/primary-key-data

- Added capability to add PrimaryKey field for a collection records
- PrimaryKey Design: #111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant