Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions sql/helpers/functions/datetime/date/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# date Helper
Specifies the `DATE` function.

#### Supported by
- [PostgreSQL](https://www.postgresql.org/docs/10/functions-formatting.html)
- [Oracle](https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions193.htm)

# Allowed Types and Usage

## as String:

Usage of `date` as **String** with the following Syntax:

**Syntax:**

```javascript
$date: < String >
```

**SQL-Definition:**
```javascript
DATE(<value-param>)
```

:bulb: **Example:**
```javascript
function() {
return sql.$select({
my_timestamp: { $date: '~~foo.column' },
$from: 'foo'
});
}

// SQL output
SELECT
DATE(foo.column) AS my_timestamp
FROM
foo

// Values
{}
```

38 changes: 38 additions & 0 deletions sql/helpers/functions/datetime/date/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

class date extends SQLBuilder.SQLHelper {
constructor(sql){
super(sql);

this.Types({
String: { syntax: this.Syntax('DATE(<value-param>)') },
});
}
}

module.exports = {
definition: date,
description: `Specifies the \`DATE\` function.`,
supportedBy: {
PostgreSQL: 'https://www.postgresql.org/docs/10/functions-formatting.html',
Oracle: 'https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions193.htm',
},
examples: {
String: {
"Basic Usage": function(sql) {
return {
test: function(){
return sql.$select({
my_timestamp: { $date: '~~foo.column' },
$from: 'foo'
});
},
expectedResults: {
sql: 'SELECT DATE(foo.column) AS my_timestamp FROM foo',
values: {}
}
}
}
},
}
}