# dbrs **Repository Path**: zfd81/dbrs ## Basic Information - **Project Name**: dbrs - **Description**: Data broker server - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-06-28 - **Last Updated**: 2022-09-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dbrs ## Language Definition ### Builtin functions #### len(obj) length of array, map or string ```js len([1,2,3,4,5]) // return 5 len("hello world") // return 11 len({foo: "bar"}) // return 1 ``` #### if(condition, if_true, if_false) if/else function ``` if(1>2, 'ok', 'no') // return 'no' if(2>1, 'ok', 'no') // return 'ok' ``` #### decode(condition, if1, then1, if2, then2,... , default) logic processing function ```js decode(23, 1, "ok1", 23, "ok2") // return "ok2" decode(23, 1, "ok1", 2, "ok2", "default") // return "default" decode(23, 1, "ok1", 2, "ok2") // return 23 decode(23, 1, "ok1", 2) // return 2 decode(23, 1, "ok1") // return 23 decode(23, 1) // return 23 decode(23) // return 23 ``` #### eq(val1, val2) equality function ```js eq(2, 3) // return false eq("str1", "str1") // return true eq(false, false) // return true eq("23", 23) // return false ``` #### string string function ##### concat(str1, str2, str3, ..., strn) string catenate ``` concat("aa", "bb", "cc") // return "aabbcc" concat("aa", 11, "22") // return "aa1122" concat("aa", 11, 22.222) // return "aa1122.222" ``` ##### lower(str) Convert string to lowercase ``` lower("AABBCC") // return "aabbcc" lower("aA") // return "aa" ``` ##### upper(str) Convert string to uppercase ``` upper("aabbcc") // return "AABBCC" upper("aA") // return "AA" ``` ##### left(str, length) returns the leftmost length characters of str ``` left("abc", -1) // return "" left("abc", 0) // return "" left("abc", 2) // return "ab" left("abc", 5) // return "abc" ``` ##### right(str, length) returns the rightmost length characters of str ``` right("abc", -1) // return "" right("abc", 0) // return "" right("abc", 2) // return "bc" right("abc", 5) // return "abc" ``` ##### lpad(str, length, padstr) left padding string ``` lpad("hello", 7, "*") // return "**hello" lpad("hello", 5, "*") // return "hello" lpad("hello", 3, "*") // return "hel" ``` ##### rpad(str, length, padstr) right padding string ``` rpad("hello", 7, "*") // return "hello**" rpad("hello", 5, "*") // return "hello" rpad("hello", 3, "*") // return "hel" ``` ##### ltrim(str) Remove spaces from the left of the string ``` ltrim(" hello") // return "hello" ``` ##### rtrim(str) Remove spaces from the right of the string ``` rtrim("hello ") // return "hello" ``` ##### trim(str) Remove spaces at the beginning and end of a string ``` trim(" hello ") // return "hello" ``` ##### replace(str, old, new) string replacement ``` replace("hello", "l", "k") // return "hekko" ``` ##### strcmp(str1, str2) string comparison - str1 > str2: return 1. - str1 < str2: return -1. - other: return 0(eg str1 == str2). ``` strcmp("ab", "ab") // return 0 strcmp("ab", "ac") // return -1 strcmp("ac", "ab") // return 1 strcmp(NULL, "ab") // return -1 ``` ##### repeat(str, count) Copy the str count times and return ``` repeat("abc", 0) // return "" repeat("abc", 1) // return "abc" repeat("abc", 2) // return "abcabc" ``` ##### reverse(str) String reverse ``` reverse("abc") // return "cba" reverse(123) // return "321" reverse("你好") // return "好你" ``` ##### insert(str, position, length, instr) replace string at specified position - str: specified string. - position: where to start being replaced. - length: length of the replaced string. - instr: new string. ``` insert("hello", 2, 2, "world") // return "hworldlo" insert("hello", 2, 4, "world") // return "hworld" ``` ##### substr(str, position, length) returns a new string that is a substring of str. - position starts from 1 ``` substr("123456", 1, 2) // return "12" substr("123456", 1, 8) // return "123456" substr("123456", 1, 0) // return "" substr("123456", 0, 2) // return "" right("abc", 5) // return "abc" ``` ##### split(str, sep) split the str into a string array by the separator sep. ``` split("ab,cd,ef", ",") // return ["ab" "cd" "ef"] split("ab,cd,ef", "") // return ["a" "b" "," "c" "d" "," "e" "f"] split(",ab,cd,ef", ",") // return ["" "ab" "cd" "ef"] split("ab,cd,ef,", ",") // return ["ab" "cd" "ef" ""] ``` ##### splitn(str, sep, n) the string str is divided into string arrays by the separator sep, and the parameter n determines the number of returned arrays - n > 0: at most n substrings; the last substring will be the unsplit remainder. - n == 0: the result is nil (zero substrings) - n < 0: all substrings ``` splitn("ab,cd,ef", ",", 5) // return ["ab" "cd" "ef"] splitn("ab,cd,ef", ",", 2) // return ["ab" "cd,ef"] splitn("ab,cd,ef", ",", 0) // return [] splitn("ab,cd,ef", ",", -1) // return ["ab" "cd" "ef"] splitn("ab,cd,ef", "", 5) // return ["a" "b" "," "c" "d,ef"] splitn(",ab,cd,ef", ",", 5) // return ["" "ab" "cd" "ef"] splitn("ab,cd,ef,", ",", 2) // return ["ab" "cd,ef,"] ``` ##### obj(str) parse JSON-encoded data and return a map object. Variable `str` is `{"name":"zfd","age":"23","tel":"180XXXXX081"}`. ```js obj(str).name // return "zfd" obj(str).age // return 23 obj(str)["tel"] // return "180XXXXX081" len(obj(str)) // return 3 ``` #### num(val) convert to numbers. ```js num("123") // return 123 num("123.55") // return 123.55 num("true") // return 1 num("false") // return 0 num(123) // return 123 num(123.55) // return 123.55 num(true) // return 1 num(false) // return 0 ``` #### datetime time type function. ##### now() returns the current datetime in 'yyyy-MM-dd HH:mm:ss' format. ``` now() // return "2022-08-26 12:50:15" ``` ##### curdate() returns the current date in 'yyyy-MM-dd' format. ``` curdate() // return "2022-08-26" ``` ##### curtime() returns the current time in 'HH:mm:ss' format. ``` curtime() // return "12:50:15" ``` ##### sysdate() returns the current system datetime in 'yyyy-MM-dd HH:mm:ss' format. ``` sysdate() // return "2022-08-26 12:50:15" ``` ##### time([datetime][,format]) return datetime object. - datetime: specified time; can be empty default is current time - format: time format; can be empty default is "yyyyMMddHHmmss" ```js time() // return "20220212125015" time("20220212125015") // return "20220212125015" time("2022-02-12 12:50:15") // error: the time format does not match because the default format is "yyyyMMddHHmmss" time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss") // return "2022-02-12 12:50:15" ``` ##### Year() returns the year in which occurs. ```js time().Year() // return 2022 time("20220212125015").Year() // return 2022 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").Year() // return 2022 ``` ##### Month() returns the month of the year specified time. ```js time().Month() // return 2 time("20220212125015").Month() // return 2 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").Month() // return 2 ``` ##### Day() returns the day of the month specified time. ```js time().Day() // return 12 time("20220212125015").Day() // return 12 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").Day() // return 12 ``` ##### YearDay() returns the day of the year specified time. ```js time().YearDay() // return 43 time("20220212125015").YearDay() // return 43 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").YearDay() // return 43 ``` ##### WeekDay() returns the day of the week specified time. ```js time().WeekDay() // return 6 time("20220212125015").WeekDay() // return 6 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").WeekDay() // return 6 ``` ##### AddHours(hours) Add hours to the specified time. ```js time("20220212125015").AddHours(7) // return "20220212195015" time("20220212125015").AddHours(-25).Day() // return 11 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").AddHours(7) // return "2022-02-12 19:50:15" ``` ##### AddDays(days) Add days to the specified time. ```js time("20220212125015").AddDays(7) // return "20220219125015" time("20220212125015").AddDays(7).Day() // return 19 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").AddDays(7) // return "2022-02-19 12:50:15" ``` ##### Operator(+) Override Add days to the specified time. ``` time("20220212125015") + 7 // return "20220219125015" (time("20220212125015") + 7).Day() // return 19 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss") + 7 // return "2022-02-19 12:50:15" ``` ##### AddMonths(months) Add months to the specified time. ```js time("20220212125015").AddMonths(7) // return "20220912125015" time("20220212125015").AddMonths(11).Month() // return 1 time("20220212125015").AddMonths(11).Year() // return 2023 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").AddMonths(7) // return "2022-09-12 12:50:15" ``` ##### DiffHour(datetime) Calculate the difference in hours. ```js time("20220212125015").DiffHour("20220212155015") // return -3 time("2022-02-12 12:50:15", "yyyy-MM-dd HH:mm:ss").DiffHour("2022-02-12 15:50:15") // return -3 ``` ##### DiffDay(datetime) Calculate the difference in days. ```js time("20220212125015").DiffDay("20220212155015") // return 0 time("20220212125015").DiffDay("20220218155015") // return -6 time("2022-03-12 12:50:15", "yyyy-MM-dd HH:mm:ss").DiffDay("2022-02-12 15:50:15") // return 28 ``` ##### Operator(-) Override Calculate the difference in days. ```js time("20220212125015") - "20220212155015" // return 0 time("20220212125015") - "20220218155015" // return -6 time("2022-03-12 12:50:15", "yyyy-MM-dd HH:mm:ss") - "2022-02-12 15:50:15" // return 28 ``` ### Slices * `array[:]` (slice) Slices can work with arrays or strings. Example: Variable `array` is `[1,2,3,4,5]`. ``` array[1:5] // return [2,3,4,5] array[3:] // return [4,5] array[:4] // return [1,2,3,4] array[:] // return array ``` ### Arithmetic Operators #### + (addition) ``` 1+22 // return 23 1+22.12345 // return 23.12345 1+'22' // return 23 '1'+'22' // return '122' ``` #### - (subtraction) ``` 23-1 // return 22 23.12345-1 // return 22.12345 '23'-1 // return 22 '23'-'1' // return 22 ``` #### * (multiplication) ``` 23*1 // return 23 23.12345*1 // return 23.12345 '23'*1 // return 23 '23'*'1' // return 23 ``` #### / (division) ``` 23/1 // return 23 23.12345/1 // return 23.12345 '23'/1 // return 23 '23'/'1' // return 23 ```