SQL source¶
The SQL database source is one of the most commonly used data sources.
In short, it presents database relations (i.e. tables
,
views
or queries
) as a entity stream to Sesam.
The SQL source has several options, all of which are presented below with their default values:
Prototype¶
{
"system": "id-of-system",
"table": "name-of-table",
"primary_key": ["list","of","key","names"],
"query": "SQL query string",
"updated_query": "SQL query string for 'since' support in queries",
"updated_column": "column-name-for-since-support-in-tables",
"whitelist": ["columns","to","include"],
"blacklist": ["columns","to","exclude"],
"fetch_size": 1000,
"preserve_null_values": false,
"schema": "default-schema-name-if-included"
}
Note
The SQL source system is purposefully read-only transactions, as to avoid side effects.
Column types¶
See the supported column types list for a overview of which RDBMS column types
are supported and how they are mapped to Sesam types. Note that if your table
or
query
property refer to relations with unsupported column types, you will either have to use the blacklist
configuration property to ignore them, or write a custom query
that coerces the non-supported column to a
supported type.
Properties¶
Property |
Type |
Description |
Default |
Req |
---|---|---|---|---|
|
String |
Must refer to a SQL system component by |
Yes |
|
|
String |
If |
Yes |
|
|
List<String> or String |
The value of this property can be a single string with the name of the column
that contains the |
||
|
List<String> or String |
Must be a valid query in the dialect of the |
||
|
String |
If the underlying relation contains information about updates, the data source is
able to support |
||
|
List<String> or String |
If the Warning The |
||
|
String |
If a specific schema within a database is needed, you must provide its name in this property.
Do not use schema names in the |
||
|
List<String> |
The names of the columns to include in the generated entities. If there is a |
||
|
List<String> |
The names of the columns to exclude from the generated entities. If there is a |
||
|
Boolean |
If set to |
False |
|
|
Integer |
The fetch size of the result sets (number of rows in a cursor fetch) to get from the database |
1000 |
|
|
Enum<String> |
Determines the behaviour of the pipe when the SQL source does not return any entities. Normally, any previously synced
entities will be deleted even if the pipe does not receive any entities from its source.
If set to The global default |
|
Continuation support¶
See the section on continuation support for more information.
Property |
Value |
---|---|
|
|
|
|
|
|
|
If this property is set to Note In practice this avoids doing an order by when doing full runs, but at the cost of not saving pipe offsets and supporting incremental deletion tracking if it fails to complete. We have seen SQL tables where only the latest rows have an value in the updated column. In that case it is not that useful to use order by and to save pipe offsets incrementally. |
Example configuration¶
The outermost object would be your pipe configuration, which is omitted here for brevity:
Example with a single table:
{
"source": {
"type": "sql",
"system": "Northwind",
"table": "Customers"
}
}
Example with a single table, where the primary key is in a column named table_id
and the updated datestamp is
in a column called updated
. This enables us to switch on since
support and as such run the SQL query "SELECT * FROM my_table WHERE updated >= :since"
:
{
"source": {
"type": "sql",
"system": "my_system",
"table": "my_table",
"primary_key": "table_id",
"updated_column": "updated"
}
}
Example with custom query:
{
"source": {
"type": "sql",
"system": "Northwind",
"query": "select * from Customers",
"primary_key": "CustomerID"
}
}
Example with a custom query from a table called my_table
where the primary key is in a column named table_id
and the updated datestamp is in a column called updated
. This enables us to switch on since
support:
{
"source": {
"type": "sql",
"system": "my_system",
"query": "select * from my_table",
"primary_key": "table_id",
"updated_column": "updated",
"updated_query": "select * from my_table where updated >= :since"
}
}