SqlHelper
Helper Class for SQL Queries
SqlHelper
Constructors
Constructor
new SqlHelper():
SqlHelper
Returns
SqlHelper
Methods
escapeDate()
staticescapeDate(date):string
Converts a date to a sql formatted string (like '2009-05-25 00:00:00.000')
Parameters
date
Date
the specified date to convert
Returns
string
- a string like "'2009-05-25 00:00:00.000'"
Static
escapeString()
staticescapeString(text):string
Converts the given string to a quoted sql string and escape all single quotes inside the string.
- Escapes single quotes
'with''(which is compatible to mssql and mariadb) - Escapes line breaks from
\r\nto\\r\\n
const sql = SqlHelper.escapeString("I'll try to write clean code");
// sql == "'I''ll try to write clean code'"
Parameters
text
string
the specified text to convert
Returns
string
- a string like "'test'"
Static
getValueAsSqlString()
staticgetValueAsSqlString(value):string
Returns a formatted string
Parameters
value
string | number | Date
Returns
string
Static
tryConvertType()
statictryConvertType(value):string|number|Date
Parameters
value
string
the string you want to convert
Returns
string | number | Date
- returns the type.
Deprecated
in v23.0.0, Please use SelectBuilder
See
SelectBuilder Check the type of the value and converts it. For example is value a number, it will return a number
Static
isSqlDateTime()
staticisSqlDateTime(value):boolean
Validate if the value string is a sql date formatted string (YYYY-MM-DD HH:mm:ss.SSS)
Parameters
value
string
the string you want to validate
Returns
boolean
- returns true if the value string is an sql date.
Static
convertStringToSqlDateTime()
staticconvertStringToSqlDateTime(date):Date
Converts a date string to an valid Date
Parameters
date
string
the string with a date
Returns
Date
- returns a date when it's in a valid format, otherwise it will return undefined.
Static
convertDateToSqlDateTimeString()
staticconvertDateToSqlDateTimeString(date):string
Converts a Date to an sql valid formatted string
Parameters
date
Date
the date you want to convert
Returns
string
- a valid sql date format
Static
guid()
staticguid():string
Returns
string