Skip to content

Commit

Permalink
update with components
Browse files Browse the repository at this point in the history
  • Loading branch information
leeduckgo committed Nov 12, 2023
1 parent 0dbe285 commit 5fb590f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/components/movespace_db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,44 @@ defmodule Components.MovespaceDB do
end

def insert_vector(vector_db_name, id_in_embedbase, raw_data, meta_data, embedding) do
IO.puts "tttttt"
IO.puts raw_data
sql_cmd = """
INSERT INTO #{vector_db_name} (id_in_embedbase, raw_data, meta_data, embedding) VALUES (
'#{id_in_embedbase}',
'#{raw_data}',
'#{handle_raw_data(raw_data)}',
'#{data_to_sql_string(meta_data)}',
'#{data_to_sql_string(embedding)}');
"""
SQL.query(Repo, sql_cmd, [])
end

def handle_raw_data(data), do: String.replace(data, "'", "''") #important
def data_to_sql_string(nil), do: "null"
def data_to_sql_string(data), do: Poison.encode!(data)

def search_data_by_id(vector_db_name, id) do
def fetch_data_by_id(vector_db_name, id) do
sql_cmd = """
SELECT * FROM #{vector_db_name} WHERE id = '#{id}';
"""
SQL.query(Repo, sql_cmd, [])
end

def search_data_by_indexer_in_embedbase(vector_db_name, id_in_embedbase) do
def fetch_data_by_id_in_embedbase(vector_db_name, id_in_embedbase) do
sql_cmd = """
SELECT * FROM #{vector_db_name} WHERE id_in_embedbase = '#{id_in_embedbase}';
"""
SQL.query(Repo, sql_cmd, [])
end

def get_count(vector_db_name) do
sql_cmd = """
SELECT COUNT(*) FROM #{vector_db_name};
"""
{:ok,
%Postgrex.Result{rows: [[count]]}} =
SQL.query(Repo, sql_cmd, [])
count
end

end

0 comments on commit 5fb590f

Please sign in to comment.