1
0
Fork 0

Add package search

This commit is contained in:
Andinus 2020-04-06 22:10:56 +05:30
parent 0121a30a7d
commit 69e919cd4e
Signed by: andinus
GPG Key ID: B67D55D482A799FD
1 changed files with 23 additions and 0 deletions

23
search/word.go Normal file
View File

@ -0,0 +1,23 @@
package search
import (
"tildegit.org/andinus/grus/storage"
)
// Word will search for unjumbled words in database, given sorted word.
func Word(sorted string, db *storage.DB) (out string, err error) {
db.Mu.RLock()
defer db.Mu.RUnlock()
stmt, err := db.Conn.Prepare("SELECT word FROM words WHERE sorted = ?")
if err != nil {
return
}
defer stmt.Close()
err = stmt.QueryRow(sorted).Scan(&out)
if err != nil {
return
}
return
}