codemonth.dk

One project every month - making stuff better ...

Semantic versioning - Verifying full version ranges

The last added function was the cmp function, which we needed to finish the overall goal, of the package: To create a "satisfies" function, that can verify if a specific version is satisfied within a range of versions.

The different ranges, that can be specified are X-ranges (Wildcard, i.e. 1.2.* or 2.*), Tilde-ranges (minimum requirements for minor versions, ~1.2.3, which will allow versions between 1.2.3 and up to 1.2.n, but not 1.3.0) and Caret-ranges and Hyphen ranges. For a full description and detailed example, you should read the following 2 articles:

So here is a quick demo, showing a variety of ranges and the outcomes.


declare
	l_semver	varchar2(150) := '1.2.3';
	procedure s(s_in varchar2)
	as
	begin
		dbms_output.put_line(s_in);
	end;
begin
	s('Checking if 1.2.3 satisfies ~1.2.1');
	if semver_ninja.satisfies('1.2.3', '~1.2.1') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 1.2.3 satisfies ~1.2');
	if semver_ninja.satisfies('1.2.3', '~1.2') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 1.2.3 satisfies ~1.2.4');
	if semver_ninja.satisfies('1.2.3', '~1.2.4') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 1.2.3 satisfies ^0.0.2');
	if semver_ninja.satisfies('1.2.3', '^0.0.2') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 0.0.3 satisfies ^0.0.2');
	if semver_ninja.satisfies('0.0.3', '^0.0.2') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 0.0.2 satisfies ^0.0.2');
	if semver_ninja.satisfies('0.0.2', '^0.0.2') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 0.1.3 satisfies ^0.1.2');
	if semver_ninja.satisfies('0.1.3', '^0.1.2') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 0.0.3 satisfies ^0.0.2 || ^0.0.1');
	if semver_ninja.satisfies('0.0.3', '^0.0.2 || ^0.0.1') then
		s('True');
	else
		s('False');
	end if;

	s('Checking if 0.0.1 satisfies ^0.0.2 || ^0.0.1');
	if semver_ninja.satisfies('0.0.1', '^0.0.2 || ^0.0.1') then
		s('True');
	else
		s('False');
	end if;
end;
/

So the result from this plsql block, will be:


Checking if 1.2.3 satisfies ~1.2.1
True
Checking if 1.2.3 satisfies ~1.2
True
Checking if 1.2.3 satisfies ~1.2.4
False
Checking if 1.2.3 satisfies ^0.0.2
False
Checking if 0.0.3 satisfies ^0.0.2
False
Checking if 0.0.2 satisfies ^0.0.2
True
Checking if 0.1.3 satisfies ^0.1.2
True
Checking if 0.0.3 satisfies ^0.0.2 || ^0.0.1
False
Checking if 0.0.1 satisfies ^0.0.2 || ^0.0.1
True

PL/SQL procedure successfully completed.

SQL>

So to complete the package, all we now is a function, that will recognize the different ranges in a string.

Tagged in : Pipelined function