edgedb-elixir icon indicating copy to clipboard operation
edgedb-elixir copied to clipboard

feat: edgeql structure generation

Open deviprsd opened this issue 2 years ago • 0 comments

https://discordapp.com/channels/841451783728529451/1152298319201173587

  1. matching on structs is easier for LSP, so instead of returning the result as a map, the generator should return it as an instance of struct. and the user can use the comparison over the actual struct in the code
  2. sometimes it can happen that elixir won't load atoms from typespecs. the current solution to this problem is the use of @schema attribute just before the query function. but this looks weird and is actually a hack
  3. the transformation of the result is done by the client and some kinda internal transform_result option. ideally the query module should do the mapping itself and not rely on the client for that
defmodule LiveBeats.EdgeDB.MediaLibrary.GetCurrentActiveSong do
 # other code
 
 defmodule Result do
   defmodule MP3 do 
    defstruct [
       :id,
       :filename,
       :filepath,
       :filesize,
       :url
     ]

     @type t() :: %__MODULE__{
       id: uuid(),
       filename: String.t(),
       filepath: String.t(),
       filesize: EdgeDB.ConfigMemory.t(),
       url: String.t()
     }
   end
   
   defmodule User do
     defstruct [
       :id,
     ]
     
     @type t() :: %__MODULE__{id: uuid()}
   end
   
   defstruct [
     :id,
     :artist,
     :title,
     :attribution,
     :date_recorded,
     :date_released,
     :paused_at,
     :played_at,
     :server_ip,
     :position,
     :inserted_at,
    :updated_at,
     :status,
     :duration,
     :mp3,
     :user,
   ]
   
   @type t() :: %__MODULE__{
     mp3: MP3.t(),
     user: User.t() | nil,
     artist: String.t(),
     title: String.t(),
     attribution: String.t() | nil,
     date_recorded: NaiveDateTime.t() | nil,
     date_released: NaiveDateTime.t() | nil,
     paused_at: DateTime.t() | nil,
     played_at: DateTime.t() | nil,
     server_ip: default__inet() | nil,
     id: uuid(),
     position: integer(),
     inserted_at: NaiveDateTime.t(),
     updated_at: NaiveDateTime.t(),
     status: default__song_status(),
     duration: duration()
   }
 end

 # rest of the code
end

Certain optimizations maybe part of a later improvement, for now the goal is get the basics generated and working.

deviprsd avatar Sep 26 '23 12:09 deviprsd