New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement a db to store data #54
Comments
Initially when creating the server routes I made separate, specific routes for each databases' routes
import { type DetaType } from "deta/dist/types/types/basic"
import { useDetaBase } from "@/composables/deta"
// need to import composable as they aren't auto imported into /server
// https://nuxt.com/docs/guide/concepts/auto-imports
import { type IPlaylist } from "@/stores"
import { chunker } from "@/utils"
type DetaPlaylist = DetaType & IPlaylist
export default defineEventHandler(async (event) => {
// calls a Deta Base put many method
// https://docs.deta.sh/docs/base/sdk/#put-many
const db = useDetaBase("playlists")
const { playlists }: { playlists: DetaPlaylist[] } = await readBody(event)
const mappedPlaylists = playlists.map(playlist => (
// if playlist is spreadable (object type)
typeof playlist === "object"
// spread it
? {
...playlist,
key: playlist.id
}
// else return empty obj
: {}
))
const chunks = chunker(mappedPlaylists, 25)
return await Promise.all(chunks.map(async chunk => await db.putMany(chunk)))
}) and import { useDetaBase } from "@/composables/deta"
// need to import composable as they aren't auto imported into /server
// https://nuxt.com/docs/guide/concepts/auto-imports
import { chunker } from "@/utils"
export default defineEventHandler(async (event) => {
// calls a Deta Base fetch method
// https://docs.deta.sh/docs/base/sdk/#fetch
const { id } = getQuery(event)
const db = useDetaBase("playlists")
if (Array.isArray(id)) {
const queries = id.map(id => ({ id }))
// no idea why
// but testing showed that db.fetch failed with 37+ queries
const chunks = chunker(queries, 37)
return await Promise.all(chunks.map(async chunk => await db.fetch(chunk)))
} else {
return await db.fetch({ id })
}
}) In the end I realized that it's probably better to match route parameters for database name (eg |
moved to #69 |
Create profile page:
|
Ask user during auth if they want data stored |
Seems more and more like data processing etc should be moved to a separate backend |
Probably something like https://docs.deta.sh/docs/base/about/
Also look into https://developer.spotify.com/documentation/general/guides/working-with-playlists/#version-control-and-snapshots
The text was updated successfully, but these errors were encountered: