parent
6ce4def6e5
commit
1e0eb1e831
@ -0,0 +1,45 @@ |
||||
// This is wrapper functtions to do requests to the api, from the frontend. |
||||
|
||||
export const apiUrl = "http://127.0.0.1:3001" |
||||
|
||||
const defaults = { |
||||
headers: {'Content-Type': 'application/json'} |
||||
}; |
||||
|
||||
export async function postNewPage() { |
||||
return fetch(`${apiUrl}/page/new`, { |
||||
method: 'POST', |
||||
...defaults |
||||
}).then((res) => res.json()) |
||||
.then((data) => data.id) |
||||
} |
||||
|
||||
export async function fetchPageList() { |
||||
return fetch(`${apiUrl}/pages`, { |
||||
method: 'GET', |
||||
...defaults |
||||
}).then((res) => res.json()) |
||||
} |
||||
|
||||
export async function fetchPage(id) { |
||||
return fetch(`${apiUrl}/page/${id}`, { |
||||
method: 'GET', |
||||
...defaults |
||||
}).then((res) => res.json()) |
||||
} |
||||
|
||||
export async function postPage({id, title, description}) { |
||||
return fetch(`${apiUrl}/page/${id}`, { |
||||
method: 'POST', |
||||
body: JSON.stringify({id: id, title: title, description: description}), |
||||
...defaults |
||||
}) |
||||
} |
||||
|
||||
export async function deletePage(id) { |
||||
return fetch(`${apiUrl}/page/${id}`, { |
||||
method: 'DELETE', |
||||
headers: {'Content-Type': 'application/json'}, |
||||
...defaults |
||||
}) |
||||
} |
@ -1,43 +1,14 @@ |
||||
export const apiUrl = "http://127.0.0.1:3001" |
||||
|
||||
const defaults = { |
||||
headers: {'Content-Type': 'application/json'} |
||||
}; |
||||
|
||||
export async function postNewPage() { |
||||
return fetch(`${apiUrl}/page/new`, { |
||||
method: 'POST', |
||||
...defaults |
||||
}).then((res) => res.json()) |
||||
.then((data) => data.id) |
||||
} |
||||
|
||||
export async function fetchPageList() { |
||||
return fetch(`${apiUrl}/pages`, { |
||||
method: 'GET', |
||||
...defaults |
||||
}).then((res) => res.json()) |
||||
} |
||||
|
||||
export async function fetchPage(id) { |
||||
return fetch(`${apiUrl}/page/${id}`, { |
||||
method: 'GET', |
||||
...defaults |
||||
}).then((res) => res.json()) |
||||
} |
||||
|
||||
export async function postPage({id, title, description}) { |
||||
return fetch(`${apiUrl}/page/${id}`, { |
||||
method: 'POST', |
||||
body: JSON.stringify({id: id, title: title, description: description}), |
||||
...defaults |
||||
}) |
||||
} |
||||
|
||||
export async function deletePage(id) { |
||||
return fetch(`${apiUrl}/page/${id}`, { |
||||
method: 'DELETE', |
||||
headers: {'Content-Type': 'application/json'}, |
||||
...defaults |
||||
}) |
||||
// New hook to make links use the react-router `navigate` method instead of default browser behavior. |
||||
|
||||
import { useNavigate } from 'react-router-dom' |
||||
|
||||
export function useFixLinks() { |
||||
// spread this return value on <a/> elements in order to make them navigate |
||||
const navigate = useNavigate(); |
||||
return { onClick: (e) => { |
||||
if (e.target.tagName != "A") { return; } |
||||
if (!e.target.href.includes(window.location.origin)) { return; } |
||||
e.preventDefault(); |
||||
navigate(e.target.href.replace(window.location.origin, "")); |
||||
}}; |
||||
} |
@ -1 +0,0 @@ |
||||
'{"statements": [{"q": ["replace into pages (id, title, description) values (?, ?, ?)", "params": [2,"main2","dummyvalue"] }], }' |
Binary file not shown.
@ -1 +1 @@ |
||||
{"id":"7de13931-444c-4dd2-a19a-5cd1e70b7f36","rows_written":109,"rows_read":1706,"storage_bytes_used":12288,"write_requests_delegated":0,"current_frame_no":108,"top_query_threshold":3,"top_queries":[{"rows_written":2,"rows_read":1,"query":"\ncreate table if not exists renders (\n id integer primary key,\n title varchar(255),\n description text\n)\n"},{"rows_written":0,"rows_read":4,"query":"select id from pages"},{"rows_written":0,"rows_read":5,"query":"select id from pages"},{"rows_written":1,"rows_read":4,"query":"\nalter table pages \nadd column html text\n"},{"rows_written":0,"rows_read":6,"query":"\nselect p.id from pages p where not exists (select r.id from renders r where p.id = r.id)\n"},{"rows_written":0,"rows_read":10,"query":"select id from pages"},{"rows_written":0,"rows_read":11,"query":"select id from pages"},{"rows_written":0,"rows_read":12,"query":"select id from pages"},{"rows_written":0,"rows_read":13,"query":"select id from pages"},{"rows_written":0,"rows_read":14,"query":"select id from pages"}],"slowest_query_threshold":0,"slowest_queries":[{"elapsed_ms":0,"query":"select id, title, description from pages where id=@val","rows_written":0,"rows_read":1},{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":1},{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":2},{"elapsed_ms":1,"query":"\nalter table pages \nadd column html text\n","rows_written":1,"rows_read":4},{"elapsed_ms":1,"query":"\ncreate table if not exists renders (\n id integer primary key,\n title varchar(255),\n description text\n)\n","rows_written":2,"rows_read":1},{"elapsed_ms":1,"query":"insert into pages (title, description) values (?, ?) returning id","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"select * from pages where id=@val","rows_written":0,"rows_read":1},{"elapsed_ms":1,"query":"select count(*) as num_pages from pages","rows_written":0,"rows_read":1},{"elapsed_ms":7,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1}],"embedded_replica_frames_replicated":0,"query_count":877,"query_latency":90259} |
||||
{"id":"7de13931-444c-4dd2-a19a-5cd1e70b7f36","rows_written":112,"rows_read":2745,"storage_bytes_used":12288,"write_requests_delegated":0,"current_frame_no":111,"top_query_threshold":3,"top_queries":[{"rows_written":2,"rows_read":1,"query":"\ncreate table if not exists renders (\n id integer primary key,\n title varchar(255),\n description text\n)\n"},{"rows_written":0,"rows_read":4,"query":"select id from pages"},{"rows_written":0,"rows_read":5,"query":"select id from pages"},{"rows_written":1,"rows_read":4,"query":"\nalter table pages \nadd column html text\n"},{"rows_written":0,"rows_read":6,"query":"\nselect p.id from pages p where not exists (select r.id from renders r where p.id = r.id)\n"},{"rows_written":0,"rows_read":10,"query":"select id from pages"},{"rows_written":0,"rows_read":11,"query":"select id from pages"},{"rows_written":0,"rows_read":12,"query":"select id from pages"},{"rows_written":0,"rows_read":13,"query":"select id from pages"},{"rows_written":0,"rows_read":14,"query":"select id from pages"}],"slowest_query_threshold":0,"slowest_queries":[{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":1},{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":2},{"elapsed_ms":1,"query":"\nalter table pages \nadd column html text\n","rows_written":1,"rows_read":4},{"elapsed_ms":1,"query":"\ncreate table if not exists renders (\n id integer primary key,\n title varchar(255),\n description text\n)\n","rows_written":2,"rows_read":1},{"elapsed_ms":1,"query":"insert into pages (title, description) values (?, ?) returning id","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"replace into pages (id, title, description, html) values (?, ?, ?, ?)","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"select * from pages where id=@val","rows_written":0,"rows_read":1},{"elapsed_ms":1,"query":"select count(*) as num_pages from pages","rows_written":0,"rows_read":1},{"elapsed_ms":7,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1}],"embedded_replica_frames_replicated":0,"query_count":1006,"query_latency":98084} |
Binary file not shown.
@ -0,0 +1,19 @@ |
||||
// helper function(s?) to make a query to the database
|
||||
|
||||
const db_url = 'http://localhost:8000' |
||||
|
||||
async function query(q, params) { |
||||
return fetch(db_url, { |
||||
method: 'POST', |
||||
headers: {'Content-Type': 'application/json'}, |
||||
body: JSON.stringify({ |
||||
statements: [{ |
||||
q: q, |
||||
params: params |
||||
}] |
||||
}) |
||||
}).then((res) => res.json()) |
||||
.then((data) => data[0].results); |
||||
} |
||||
|
||||
module.exports = { query: query }; |
Loading…
Reference in new issue