Last active
October 6, 2019 19:46
-
-
Save arathnim/b90aa9796be9579645a13e3a9c06ebeb to your computer and use it in GitHub Desktop.
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
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 /> : '...'; | |
} |
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
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