Database to use to implement the DataStore

Property definitions

linux :: data_store $ DataStore :: db
	# Database to use to implement the `DataStore`
	fun db: nullable Sqlite3DB
	do
		var db = db_cache
		if db != null then return db

		# Find DB path
		var config_home = xdg_basedir.config_home.to_s
		var config_dir = config_home.join_path(sys.program_name.basename)
		if not config_dir.file_exists then config_dir.mkdir
		var db_path = config_dir.join_path(db_file)

		# Open DB connection
		db = new Sqlite3DB.open(db_path)
		if not db.is_open then
			print_error "Data store unavaible, cannot load/save data. (at '{db_path}' with '{db.error or else "unknown"}')"
			return null
		end

		# Create DB table
		db.create_table "IF NOT EXISTS {db_table} (key TEXT PRIMARY KEY, value TEXT)"

		db_cache = db
		return db
	end
lib/linux/data_store.nit:35,2--59,4