Skip to content

Conversation

@NHDaly
Copy link
Member

@NHDaly NHDaly commented Mar 16, 2022

@bradlo: this is just a very small mechanical change - it doesn't change anything about how the SDK is set up, it just makes the TransactionResult object slightly easier to use at the REPL. 😊


If you implement Base.getproperty(), you're supposed to also implement
Base.propertynames(). Of course it's hard to know you're supposed to
do that because julia doesn't have interfaces :P

From the help docstring:

help?> Base.propertynames
  propertynames(x, private=false)

  Get a tuple or a vector of the properties (x.property) of an object
  x. This is typically the same as fieldnames(typeof(x)), but types
  that overload getproperty should generally overload propertynames
  as well to get the properties of an instance of the type.

  propertynames(x) may return only "public" property names that are
  part of the documented interface of x. If you want it to also
  return "private" fieldnames intended for internal use, pass true
  for the optional second argument. REPL tab completion on x. shows
  only the private=false properties.

  See also: hasproperty, hasfield.

This allows you to discover, at the repl, how to use these types, via
tab-complete:

julia> r = TransactionResult(exec(config..., """2+2"""))
// output Int64
4

julia> r.  # <tab>
aborted     actions      debug_level  output       problems     relations    type
julia> rr = r.relations[1]
// output Int64
4

julia> rr.  # <tab>
columns name     rel_key  type
julia> rr.columns
1-element JSON3.Array{JSON3.Array, Vector{UInt8}, SubArray{UInt64, 1, Vector{UInt64}, Tuple{UnitRange{Int64}}, true}}:
 [4]

If you implement Base.getproperty(), you're supposed to also implement
Base.propertynames(). Of course it's hard to _know_ you're supposed to
do that because julia doesn't have interfaces :P

From the help docstring:
```julia

help?> Base.propertynames
  propertynames(x, private=false)

  Get a tuple or a vector of the properties (x.property) of an object
  x. This is typically the same as fieldnames(typeof(x)), but types
  that overload getproperty should generally overload propertynames
  as well to get the properties of an instance of the type.

  propertynames(x) may return only "public" property names that are
  part of the documented interface of x. If you want it to also
  return "private" fieldnames intended for internal use, pass true
  for the optional second argument. REPL tab completion on x. shows
  only the private=false properties.

  See also: hasproperty, hasfield.
```

This allows you to discover, at the repl, how to use these types, via
tab-complete:
```julia
julia> r = TransactionResult(exec(config..., """2+2"""))
// output Int64
4

julia> r.  # <tab>
aborted     actions      debug_level  output       problems     relations    type
julia> rr = r.relations[1]
// output Int64
4

julia> rr.  # <tab>
columns name     rel_key  type
julia> rr.columns
1-element JSON3.Array{JSON3.Array, Vector{UInt8}, SubArray{UInt64, 1, Vector{UInt64}, Tuple{UnitRange{Int64}}, true}}:
 [4]

```
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.

1 participant