Skip to content

Commit

Permalink
working!
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Dec 13, 2023
1 parent 4107801 commit eaa0211
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions public/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@
loading = false;
}
const selectDb = async (tenant) => {
const selectDb = async (tenant) => {
console.log("selecting tenant",tenant);
loading = true;
currentTenant = tenant;
data = await fetch('d1/'+tenant.name);
console.log(`fetching d1/${tenant.name}`);
let response = await fetch('d1/'+tenant.name);
console.log(response);
if (response.status == 200) {
var payload = await response.text();
console.log(payload);
var dat = JSON.parse(payload);
console.log(dat);
data = dat;
}
loading = false;
console.log('db selected');
}
const createDb = async () => {
Expand All @@ -73,9 +84,10 @@
"id":dataId,
"data":dataValue
};
await fetch('d1/'+currentTenant.name,{method:"POST", body:JSON.stringify(payload)});
await fetch('d1/'+currentTenant.name,{method:"PUT", body:JSON.stringify(payload)});
dataId="";
dataValue="";
await selectDb(currentTenant);
loading = false;
}
Expand Down
4 changes: 2 additions & 2 deletions public/_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ router.get('/d1/:tenant', withParams, async (request, env) => {

// add a data row for a given tenant
// should be a PUT
router.post('/d1/:tenant', withParams, withContent, async (request, env) => {
router.put('/d1/:tenant', withParams, withContent, async (request, env) => {
try {
var tenant = request.params.tenant
var data = await request.json()
console.log('*************************************')
console.log('*************************************')
var d1Fromcontext = context.env[tenant]
var d1Fromcontext = env[tenant.toUpperCase()]
console.log('d1Fromcontext', d1Fromcontext)
await d1Fromcontext
.prepare(
Expand Down

0 comments on commit eaa0211

Please sign in to comment.