\ Server-wide variables autosavable in database

: sv@ ( var-name -- value )
	"SELECT `value` FROM `server_variables` WHERE `type` = 'svalue' AND `name` LIKE '[ >slashes ]';" parse
	query ?dup if type exit then
	dup list# 0= if drop null exit then
	0 list@ "value" m@
;

: sv-del ( var-name -- )
	"DELETE FROM `server_variables` WHERE `type` = 'svalue'	AND `name` LIKE '[ >slashes ]';" parse
	update ?dup if type else drop then
;

: sv! ( value var-name -- )
	over null? if  nip sv-del exit	then
		
	"REPLACE `server_variables` SET `type`='svalue', `name` = '[ >slashes ]', `value` = '[ >slashes ]';" parse
	update ?dup if type else drop then
;

new-list svalue sv-list

: svalue  ( val -- \ name )
	value
	last-word sv-list list+
	last-word sv@ 
	?dup null? not if
		"to " last-word s+ eval
	then
;

: sv-save ( name -- )
	dup eval swap sv!
;

: sv-save-all  ( -- )
	sv-list ['] sv-save do-list
;

on-jbf-stop: sv-save-all
