Skip to content

Instantly share code, notes, and snippets.

@arathnim
Last active October 6, 2019 19:46
Show Gist options
  • Save arathnim/b90aa9796be9579645a13e3a9c06ebeb to your computer and use it in GitHub Desktop.
Save arathnim/b90aa9796be9579645a13e3a9c06ebeb to your computer and use it in GitHub Desktop.
const NoteList = () => {
const [loading, notes] = useQuery(
api => api.notes.all().select('{ id title }')
)
return loading ? <Loading /> : '...';
}
const Note = ({id}) => {
const [loading, note] = useQuery(
api => api.notes.get(id).select('{ title content }')
)
const deleteNote = useMutation(
api => api.notes.get(id).delete()
)
const updateNote = useMutation(
(api, title, content) => api.notes.get(id).update({title, content})
)
return loading ? <Loading /> : '...';
}
thing.schema = db =>
Promise.all([
db.schema
.createTable('notes', table => {
table.increments('noteID').primary()
table.string('title', 512)
table.text('contents')
}),
db.createIndex('textsearch', 'notes', 'search')
])
thing.api = db =>
Promise.all([
db.exposeKeyValueStore(db.table('notes')),
db.exposeTextSearch(db.index('textsearch')),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment