-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import { createApiClient } from '@accentor/api-client-js' | ||
import type { App } from 'vue' | ||
|
||
export default { | ||
install: (app: App) => { | ||
let url: string | ||
if (import.meta.env.VITE_APP_API_URL != undefined) { | ||
url = import.meta.env.VITE_APP_API_URL | ||
} else if (import.meta.env.PROD) { | ||
url = '/api' | ||
} else { | ||
url = 'http://localhost:3000/api' | ||
} | ||
app.provide('apiBaseUrl', url) | ||
app.provide('api', createApiClient(url)) | ||
} | ||
let url: string | ||
if (import.meta.env.VITE_APP_API_URL != undefined) { | ||
url = import.meta.env.VITE_APP_API_URL | ||
} else if (import.meta.env.PROD) { | ||
url = '/api' | ||
} else { | ||
url = 'http://localhost:3000/api' | ||
} | ||
|
||
export const baseURL = url | ||
|
||
export default createApiClient(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type SqliteClient from '@/db-client' | ||
import api from '@/api' | ||
import { useAuthStore } from '@/stores/auth' | ||
import type { UnwrapNestedRefs } from 'vue' | ||
|
||
export default class UserDao { | ||
client: SqliteClient | ||
authStore: UnwrapNestedRefs<{ secret: string | null; deviceId: string | null }> | ||
|
||
constructor(client: SqliteClient) { | ||
this.client = client | ||
this.authStore = useAuthStore() | ||
} | ||
|
||
async refresh() { | ||
let done = false | ||
const generator = api.users.index({ | ||
secret: this.authStore.secret!, | ||
device_id: this.authStore.deviceId! | ||
}) | ||
while (!done) { | ||
const obj = await generator.next() | ||
for (const row of obj.value) { | ||
await this.client.executeMutation( | ||
'users', | ||
'INSERT INTO users VALUES (?, ?, ?) ON CONFLICT(id) DO UPDATE SET name=?, permission=?;', | ||
row.id, | ||
row.name, | ||
row.permission, | ||
row.name, | ||
row.permission | ||
) | ||
} | ||
done = obj.done! | ||
} | ||
} | ||
|
||
getAll() { | ||
return this.client.executeSelect(['users'], 'SELECT * FROM users;') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,11 @@ | ||
<script setup lang="ts"> | ||
import { inject, ref } from 'vue' | ||
import type SqliteClient from '../db-client' | ||
const dbClient: SqliteClient = inject('db')! | ||
const minA = ref(0) | ||
const minB = ref(0) | ||
const minC = ref(0) | ||
const values = dbClient.executeSelect( | ||
['test'], | ||
'SELECT * FROM test WHERE a >= ? AND b >= ? AND c >= ? ORDER BY a ASC LIMIT ?;', | ||
minA, | ||
minB, | ||
minC, | ||
10 | ||
) | ||
async function deleteAll() { | ||
await dbClient.executeMutation('test', 'DELETE FROM test;') | ||
} | ||
function randInt(max: number): number { | ||
return Math.round(Math.random() * max) | ||
} | ||
async function insertNew() { | ||
await dbClient.executeMutation( | ||
'test', | ||
'INSERT INTO test VALUES (?, ?, ?);', | ||
randInt(100), | ||
randInt(50), | ||
randInt(10) | ||
) | ||
} | ||
import { inject } from 'vue' | ||
import type UserDao from '@/db/user_dao' | ||
const { users }: { users: UserDao } = inject('db')! | ||
const values = users.getAll() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div>Table contents: {{ values }}</div> | ||
<div> | ||
<v-text-field v-model.number="minA" type="number" /> | ||
<v-text-field v-model.number="minB" type="number" /> | ||
<v-text-field v-model.number="minC" type="number" /> | ||
<v-btn @click="deleteAll">Delete all</v-btn> | ||
<v-btn @click="insertNew">Insert new</v-btn> | ||
</div> | ||
</div> | ||
<p>Home</p> | ||
<div>Table contents: {{ values }}</div> | ||
</template> |