Commits

Yang Zhang committed fb2b9f8

finish @ feature

Comments (0)

Files changed (1)

 
     @staticmethod
     def get_user_startswith(word):
-        return jsonify(users = [dict(nickname="thisistest1",id=1),
-                        dict(nickname="thisistest2",id=1),
-                        dict(nickname="thisistest3",id=1),
-                        dict(nickname="thisistest4",id=1),
-                        dict(nickname="thisistest5",id=1)]
-        )
+        c = g.db.cursor()
+        c.execute("SELECT id,nickname FROM user \
+                    WHERE nickname LIKE :word LIMIT 5",{'word':'%'+word+'%'})
+        results = c.fetchall()
+        lst = []
+        for result in results:
+            d = {}
+            d['nickname'] = result['nickname']
+            d['id'] = result['id']
+            lst.append(d)
+        return jsonify(users = lst)
         
     def update_email_nickname(self):
         c = g.db.cursor()