   defp encode_fields(fields, offset) do
     fields =
       for {name, value} <- fields do
-        field = named_field(name: name, data_type: :string)
-        value = encode_type(value, :string)
+        type = infer_type_from_term(value)
+        field = named_field(name: name, data_type: type)
+        value = encode_type(value, type)
         {field, value}
       end
 


  defp field_name(field) when is_record(field, :named_field), do: named_field(field, :name)

  # http://orientdb.com/docs/last/Types.html
  defp int_to_type(0),  do: :boolean
  defp int_to_type(1),  do: :sint32
  defp int_to_type(2),  do: :sint16
  defp int_to_type(3),  do: :sint64
  defp int_to_type(4),  do: :float
  defp int_to_type(5),  do: :double
  defp int_to_type(6),  do: :datetime
  defp int_to_type(7),  do: :string
  defp int_to_type(8),  do: :binary
  defp int_to_type(9),  do: :embedded
  defp int_to_type(10), do: :embedded_list
  defp int_to_type(11), do: :embedded_set
  defp int_to_type(12), do: :embedded_map
  defp int_to_type(13), do: :link
  defp int_to_type(14), do: :link_list
  defp int_to_type(15), do: :link_set
  defp int_to_type(16), do: :link_map
  defp int_to_type(17), do: :embedded_list
  defp int_to_type(18), do: :byte
  defp int_to_type(19), do: :transient
  defp int_to_type(20), do: :custom
  defp int_to_type(21), do: :decimal
  defp int_to_type(22), do: :link_bag
  defp int_to_type(23), do: :any
end

        end
    end

    {build_fields(fields_and_values), rest}
  end

  defp build_fields(fields_and_values) do
    for {field, value} <- fields_and_values, into: %{} do
      {named_field(field, :name), value}
    end
  end

