import time import random import jwt from space_api import API api = API('demo', 'localhost:4124') SECRET = 'my_secret' api.set_token( jwt.encode({ "password": "******" }, SECRET, algorithm='HS256').decode('utf-8')) db = api.my_sql() for i in range(10): response = db.insert('demo').doc({ "id": i + 100, "device": 2, "value": random.randint(11, 20) }).apply() if response.status == 200: print("Sent") else: print(response.error) time.sleep(2)
import jwt from space_api import API api = API('books-app', 'localhost:4124') db = api.my_sql() api.set_token( jwt.encode({ "password": "******" }, 'my_secret', algorithm='HS256').decode('utf-8')) print(db.get('books').apply())
import time import random from space_api import API, COND import variables api = API(variables.app, variables.url) db = variables.db(api) db.delete('books').apply() def func(op_sel, i): if op_sel == 0: return db.insert('books').doc({ variables.id: i, "name": "MyBook" + str(i), "author": "Author" + str(i) }).apply() elif op_sel == 1: return db.update('books').set({ "author": "myself" + str(i) }).where(COND(variables.id, "==", i)).apply() elif op_sel == 2: return db.delete_one('books').where(COND(variables.id, "==", i)).apply() else: return db.get('books').apply() while True: sel = random.randint(0, 3) id = random.randint(0, 9)
import jwt from space_api import API, COND api = API('demo', 'localhost:8081') SECRET = 'my_secret' api.set_token( jwt.encode({ "password": "******" }, SECRET, algorithm='HS256').decode('utf-8')) db = api.my_sql() service = api.service('login_service') def login(params, auth, cb): response = db.get_one('demo_users').where( COND("username", "==", params["username"])).apply() if response.status == 200: res = response.result if res["username"] == params["username"] and res["password"] == params[ "password"]: cb( 'response', { 'ack': True, 'token': jwt.encode( { "username": res["username"],
# UPDATE from space_api import API, AND, OR, COND api = API("books-app", "localhost:4124") db = api.my_sql() # The condition to be matched condition = COND("author", "==", "author1") # Update the books response = db.update("books").where(condition).set({"name": "A book"}).apply() if response.status == 200: print("Success") else: print(response.error) # ---------------------------------------------------------------------------------------------------- # UPDATE ONE from space_api import API, AND, OR, COND api = API("books-app", "localhost:4124") db = api.my_sql() # The condition to be matched condition = COND("author", "==", "author1") # Update the books response = db.update_one("books").where(condition).set({"name": "A book"}).apply() if response.status == 200: print("Success")