Esempio n. 1
0
	def put(self,serial):
		print(serial)
		description = request.json['description']
		print(description)
		session.query(Device).filter_by(serial=serial).update({'description':description})
		session.commit()

		smartlab_device = session.query(Device).filter_by(serial=serial).first()
		data = {}
		data['serial'] = smartlab_device.serial
		data['description'] = smartlab_device.description
		data['date'] = str(smartlab_device.date)
		json_data = json.dumps(data)
		return json_data
Esempio n. 2
0
 def get(self):
     print('query all devices:')
     smartlab_devices = session.query(Device)
     device_array = []
     for device in smartlab_devices:
         device_array.append(device.serial)
     device_dict = {}
     device_dict["devices"] = device_array
     return json.dumps(device_dict)
Esempio n. 3
0
	def get(self,serial):
		print(serial)
		print('query one device:')
		smartlab_device = session.query(Device).filter_by(serial=serial).first()
		data = {}
		data['serial'] = smartlab_device.serial
		data['description'] = smartlab_device.description
		data['date'] = str(smartlab_device.date)
		json_data = json.dumps(data)
		return json_data
Esempio n. 4
0
	def delete(self,serial):
		print(serial)
		session.query(Device).filter_by(serial=serial).delete()
		session.commit()
		return serial
Esempio n. 5
0
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

if action == "insert":
    device = Device('SN0001', 'GPS Garmin')
    session.add(device)
    session.commit()

    device = Device('SN0002', 'Battery 3.3V')
    session.add(device)
    session.commit()

if action == "read":
    #query one device
    print('query one device:')
    smartlab_device = session.query(Device).filter_by(serial='SN0001').first()
    print(smartlab_device.serial, "-", smartlab_device.description)

    #query all devices
    print('query all devices:')
    smartlab_devices = session.query(Device)
    for device in smartlab_devices:
        print(device.serial, "-", device.description)

if action == "delete":
    session.query(Device).filter_by(serial='SN0001').delete()
    session.commit()

if action == "update":
    session.query(Device).filter_by(serial='SN0001').update(
        {'description': 'GPS Atmel'})