Designing Table and Data For Folder Structure To Be Use On User Interface

I need to design a web page where it involve tree structure/ directory structure, each folder / file will be a record. So what will be the best way to query what I needed? Below have a solution which is quite useful.


Requirement will be like this:

> categoryA [dir]

    > hostA [dir]
    • > file.txt
    > hostB
    • > file.txt

> categoryB

    > hostA
    • > file.txt

> categoryC

    > hostA
    • > file.txt


Main table fields beside the necessary fields as per below.

Each parent’s Path will be child’s Directory, Inheriting from parent.

table structure for folder structure





With above result, how can to query the data? :


  1. is_dir: true
  2. ref_key: root
  3. reference: Server.Profile


  1. is_dir: true
  2. reference: Server.Profile
  3. With each Category name I have, ref_name: Category name
  4. With each Category path I have, directory: Category path


  1. reference: Server.Profile
  2. is_dir: false
  3. With each Host name I have, ref_name: Host name
  4. With each Host path I have, directory: Host path



_.imodFSServerProfileAddContent = function (fqdn, category, fileName, fileContent, overwrite) {
	var _ = this;
		var tbl = _.tblIMoDFileSystem;

		if (_.isNullOrEmpty(fileContent)) fileContent = '';
		if (!_.isString(fileContent)) throw 'file content must be a string';
		if (_.isNullOrEmpty(fileName)) {
			var fileName = _.dtString(new Date());
			fileName = _.rpl(fileName, '-', '');
			fileName = _.rpl(fileName, ' ', '-');
			fileName = _.rpl(fileName, ':', '') + '.fs';

		var hostName = _.takeBefore(fqdn, '.').toUpperCase();
		var domain = _.takeAfter(fqdn, '.').toUpperCase();

		var catCategory = _.fmt('/{0}', category).toLowerCase();
		var rcCategory = {
			reference: _._imodFSServerProfile,
			ref_key: 'root',
			path: catCategory,
			directory: '',
			is_dir: true,
			name: category
		var grCategory = _.grFirst(tbl, rcCategory);
		if (_.isNullOrEmpty(grCategory)) grCategory = _.grInsert(tbl, rcCategory, true);

		var catHost = _.fmt('/{0}/{1}', category, hostName).toLowerCase();
		var rcHost = {
			reference: _._imodFSServerProfile,
			ref_key: category, //must be uppercase
			path: catHost, //must be all lowercase
			directory: catCategory, //must be all lowercase
			is_dir: true,
			name: hostName
		var grHost = _.grFirst(tbl, rcHost);
		if (_.isNullOrEmpty(grHost)) grHost = _.grInsert(tbl, rcHost, true);

		var ext = _.takeLastAfter(fileName, '.');
		if (ext == fileName) ext = null;

		var catFile = _.fmt('/{0}/{1}/{2}', category, hostName, fileName);
		var rcFile = {
			reference: _._imodFSServerProfile,
			ref_key: hostName,
			path: catFile,
			directory: catHost.toLowerCase(),
			is_dir: false,
			name: fileName,
			length: fileContent.length,
			fs_content_type: 'application/octet-stream',
			extension: ext
		var grFile = _.grFirst(tbl, rcFile);
		if (_.isNullOrEmpty(grFile)) grFile = _.grInsert(tbl, rcFile, true);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.