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

AttributeType constructor should run with Label #71

Closed
FrankUrbach opened this issue May 1, 2021 · 3 comments
Closed

AttributeType constructor should run with Label #71

FrankUrbach opened this issue May 1, 2021 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@FrankUrbach
Copy link
Collaborator

To build a Attribute the building block for the constructor is a Label. Until now the constructor requires a string that isn't given by the function calling the constructor. Excuse the ending txt in the pinned file. But GitHub didn't support .jl files.
AttributeType.txt

@FrankUrbach FrankUrbach added the bug Something isn't working label May 1, 2021
@FrankUrbach FrankUrbach added this to To do in TypeDBClient V1 via automation May 1, 2021
@FrankUrbach FrankUrbach added this to the Version 1.0 milestone May 1, 2021
@mkschulze
Copy link
Member

mkschulze commented May 1, 2021

Just include the code instead of the textfile if it isn't too long.

# This file is a part of TypeDBClient.  License is MIT: https://github.com/Humans-of-Julia/TypeDBClient.jl/blob/main/LICENSE

struct AttributeType{V} <: AbstractAttributeType
    label::Label
    is_root::Bool
end

# More convenient for reference
const VALUE_TYPE = Proto.AttributeType_ValueType

# Encode the value type (as defined in VALUE_TYPE) in the type parameter
function AttributeType(label::Label, is_root::Bool, value_type::EnumType)
    AttributeType{value_type}(label, is_root)
end

# Define conversion functions
let
    function _as_something(value_type::EnumType)
        return function(t::AttributeType{V}) where {V}
            t.is_root || throw(TypeDBClientException(INVALID_CONCEPT_CASTING, V))
            return AttributeType(Label("attribute"), true, value_type)
        end
    end

    global as_boolean   = _as_something(VALUE_TYPE.BOOLEAN)
    global as_long      = _as_something(VALUE_TYPE.LONG)
    global as_double    = _as_something(VALUE_TYPE.DOUBLE)
    global as_string    = _as_something(VALUE_TYPE.STRING)
    global as_date_time = _as_something(VALUE_TYPE.DATETIME)
end

proto(::AttributeType{V}) where {V} = V

# TODO What is Object value type in Java? It needs to return `false` for that.
is_writable(::AttributeType) = true
is_writable(::AttributeType{VALUE_TYPE.OBJECT}) = false

is_keyable(::AttributeType) = false
is_keyable(::AttributeType{VALUE_TYPE.LONG}) = true

@tk3369
Copy link
Member

tk3369 commented May 1, 2021

OK to keep that change. Thanks

@FrankUrbach
Copy link
Collaborator Author

Ok. I will merge this with the next merge to main.

TypeDBClient V1 automation moved this from To do to Done May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

3 participants