CREATE TABLE
  IF NOT EXISTS `domain` (
    `id` integer PRIMARY KEY autoincrement,
    `domain` TEXT NOT NULL,
    `action` TEXT NOT NULL,
    `isUsing` INTEGER DEFAULT 1
  );

INSERT INTO
  domain (domain, `action`)
VALUES
  ("*.loc", "127.0.0.3");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("*.v-search.loc", "127.0.0.1");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("home.abc.loc", "127.0.5.100");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("abc.loc", "127.0.5.10");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("*.abc.loc", "127.0.5.1");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("ban.abc.loc", "ban");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("*.ban.loc", "ban");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("*.i192.loc", "i192");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("aa./^\\d{1,3}$/.num.loc", "192.168.1.3");

INSERT INTO
  domain (domain, `action`)
VALUES
  ("bb./^\\D{1,2}$/.num.loc", "192.168.1.4");

/*  --------------------------------------------------------------------------*/
--
--
/*dns*/
CREATE TABLE
  IF NOT EXISTS `dns` (
    `id` integer PRIMARY KEY autoincrement,
    `ip` TEXT NOT NULL,
    `description` TEXT,
    `isUsing` INTEGER DEFAULT 1
  );

INSERT INTO
  dns (`ip`, `description`)
VALUES
  ("8.8.8.8", "google");

--
INSERT INTO
  dns (`ip`, `description`)
VALUES
  ("112.124.47.27", "OneDNS 南方");

--
INSERT INTO
  dns (ip, `description`)
VALUES
  ("114.215.126.16", "OneDNS 北方");

--
INSERT INTO
  dns (ip, `description`)
VALUES
  ("223.5.5.5", "阿里");

INSERT INTO
  dns (ip, `description`)
VALUES
  ("114.114.114.114", "114");

--
/*-----------------------------------------------------*/
---
---
CREATE TABLE
  IF NOT EXISTS `code` (
    `id` integer PRIMARY KEY autoincrement,
    `name` TEXT NOT NULL,
    `code` TEXT NOT NULL,
    `isUsing` INTEGER DEFAULT 1
  );

--
-- SET @demo=
INSERT INTO
  code (`name`, `code`)
VALUES
  (
    "all",
    '
function demo(domain, ban, msg) {
  let n = Number(domain[0]) || 0;
  if (0 < n && n < 255) {
    // return ip or [ ip1 , ip2 ];
    return `192.168.12.${n}`;
  }
  if (/^\d+$/.test(domain[0])) {
    // return null
    // No results found
    // Leave it to other steps to continue searching
    return null;
  }
  // End the search, the final result is empty;
  // no ip match
  return ban;
}

function i192(domain, ban, msg) {
    let n = Number(domain[0]) || 0;
    return `192.168.12.${n}`;
}
'
  );

/**/
-- INSERT INTO
--   TABLE_NAME (domain, action)
-- VALUES
--   (value1, value2, value3,...valueN);
-- CREATE TABLE domain (domain TEXT, action TEXT);