|
@@ -8,9 +8,10 @@ This plugin must be used in conjunction with at least a database driver. We are
|
|
|
This [repository](https://github.com/lf-edge/ekuiper/tree/master/extensions/sqldatabase/driver) lists all the supported drivers.
|
|
|
|
|
|
This plugin supports `sqlserver\postgres\mysql\sqlite3\oracle` drivers by default. User can compile plugin that only support one driver by himself,
|
|
|
-for example, if he only wants sqlserver, then he can build with build tag `sqlserver`.
|
|
|
+for example, if he only wants sqlserver, then he can build with build tag `sqlserver`.
|
|
|
|
|
|
### Default build command
|
|
|
+
|
|
|
```shell
|
|
|
# cd $eKuiper_src
|
|
|
# go build -trimpath -modfile extensions.mod --buildmode=plugin -o plugins/sources/Sql.so extensions/sources/sql/sql.go
|
|
@@ -18,6 +19,7 @@ for example, if he only wants sqlserver, then he can build with build tag `sqlse
|
|
|
```
|
|
|
|
|
|
### Sqlserver build command
|
|
|
+
|
|
|
```shell
|
|
|
# cd $eKuiper_src
|
|
|
# go build -trimpath -modfile extensions.mod --buildmode=plugin -tags sqlserver -o plugins/sources/Sql.so extensions/sources/sql/sql.go
|
|
@@ -58,6 +60,7 @@ template_config:
|
|
|
indexFieldType: "DATETIME"
|
|
|
dateTimeFormat: "YYYY-MM-dd HH:mm:ssSSS"
|
|
|
```
|
|
|
+
|
|
|
### Global configurations
|
|
|
|
|
|
User can specify the global sql source settings here. The configuration items specified in `default` section will be taken as default settings for the source when running this source.
|
|
@@ -71,14 +74,15 @@ The interval (ms) to issue a query.
|
|
|
The target database url
|
|
|
|
|
|
| database | url sample |
|
|
|
-|------------|-------------------------------------------------------|
|
|
|
+| ---------- | ----------------------------------------------------- |
|
|
|
| mysql | mysql://user:test@140.210.204.147/user?parseTime=true |
|
|
|
-| sql server | sqlserver://username:password@140.210.204.147/testdb |
|
|
|
+| sql server | sqlserver://username:password@140.210.204.147/testdb |
|
|
|
| postgres | postgres://user:pass@localhost/dbname |
|
|
|
| postgres | postgres://user:pass@localhost/dbname |
|
|
|
| sqlite | sqlite:/path/to/file.db |
|
|
|
|
|
|
### internalSqlQueryCfg
|
|
|
+
|
|
|
* `table`: table name to query
|
|
|
* `limit`: how many items need fetch from the result
|
|
|
* `indexField`: which column for the table act as index to record the offset
|
|
@@ -86,29 +90,29 @@ The target database url
|
|
|
* `indexFieldType`: column type for the indexField, if it is dateTime type, must set this field with `DATETIME`
|
|
|
* `dateTimeFormat`: data time format for the index field
|
|
|
|
|
|
-
|
|
|
-| table | limit | indexField | indexValue | indexFieldType | dateTimeFormat | sql query statement |
|
|
|
-|----------|-------|--------------|-----------------------|-----------------|-----------------------------|-----------------------------------------------------------------------------------------------------|
|
|
|
-| Student | 10 | | | | | select * from Student limit 10 |
|
|
|
-| Student | 10 | stun | 100 | | | select * from Student where stun > 100 limit 10 |
|
|
|
-| Student | 10 | registerTime | "2022-04-21 10:23:55" | "DATETIME" | "YYYY-MM-dd HH:mm:ss" | select * from Student where registerTime > '2022-04-21 10:23:55' order by registerTime ASC limit 10 |
|
|
|
-
|
|
|
+| table | limit | indexField | indexValue | indexFieldType | dateTimeFormat | sql query statement |
|
|
|
+| ------- | ----- | ------------ | --------------------- | -------------- | --------------------- | --------------------------------------------------------------------------------------------------- |
|
|
|
+| Student | 10 | | | | | select * from Student limit 10 |
|
|
|
+| Student | 10 | stun | 100 | | | select * from Student where stun > 100 limit 10 |
|
|
|
+| Student | 10 | registerTime | "2022-04-21 10:23:55" | "DATETIME" | "YYYY-MM-dd HH:mm:ss" | select * from Student where registerTime > '2022-04-21 10:23:55' order by registerTime ASC limit 10 |
|
|
|
|
|
|
### templateSqlQueryCfg
|
|
|
+
|
|
|
* `TemplateSql`: sql statement template
|
|
|
* `indexField`: which column for the table act as index to record the offset
|
|
|
* `indexValue`: initial index value, if user specify this field, the query will use this initial value as query condition, will update next query when get a greater value.
|
|
|
* `indexFieldType`: column type for the indexField, if it is dateTime type, must set this field with `DATETIME`
|
|
|
* `dateTimeFormat`: data time format for the index field
|
|
|
|
|
|
+::: v-pre
|
|
|
+| TemplateSql | indexField | indexValue | indexFieldType | dateTimeFormat | sql query statement |
|
|
|
+| ------------------------------------------------------------------------------------------------- | ------------ | --------------------- | -------------- | --------------------- | --------------------------------------------------------------------------------------------------- |
|
|
|
+| select * from Student limit 10 | | | | | select * from Student limit 10 |
|
|
|
+| select * from Student where stun > {{.stun}} limit 10 | stun | 100 | | | select * from Student where stun > 100 limit 10 |
|
|
|
+| select * from Student where registerTime > '{{.registerTime}}' order by registerTime ASC limit 10 | registerTime | "2022-04-21 10:23:55" | "DATETIME" | "YYYY-MM-dd HH:mm:ss" | select * from Student where registerTime > '2022-04-21 10:23:55' order by registerTime ASC limit 10 |
|
|
|
+:::
|
|
|
|
|
|
-| TemplateSql | indexField | indexValue | indexFieldType | dateTimeFormat | sql query statement |
|
|
|
-|---------------------------------------------------------------------------------------------------|--------------|-----------------------|-----------------|-----------------------------|-----------------------------------------------------------------------------------------------------|
|
|
|
-| select * from Student limit 10 | | | | | select * from Student limit 10 |
|
|
|
-| select * from Student where stun > {{.stun}} limit 10 | stun | 100 | | | select * from Student where stun > 100 limit 10 |
|
|
|
-| select * from Student where registerTime > '{{.registerTime}}' order by registerTime ASC limit 10 | registerTime | "2022-04-21 10:23:55" | "DATETIME" | "YYYY-MM-dd HH:mm:ss" | select * from Student where registerTime > '2022-04-21 10:23:55' order by registerTime ASC limit 10 |
|
|
|
-
|
|
|
-### *Note*: users only need set internalSqlQueryCfg or templateSqlQueryCfg, if both set, templateSqlQueryCfg will be used
|
|
|
+### *Note*: users only need set internalSqlQueryCfg or templateSqlQueryCfg, if both set, templateSqlQueryCfg will be used
|
|
|
|
|
|
## Override the default settings
|
|
|
|
|
@@ -118,9 +122,8 @@ If you have a specific connection that need to overwrite the default settings, y
|
|
|
|
|
|
```
|
|
|
demo (
|
|
|
- ...
|
|
|
- ) WITH (DATASOURCE="demo", FORMAT="JSON", CONF_KEY="template_config", TYPE="sql");
|
|
|
+ ...
|
|
|
+ ) WITH (DATASOURCE="demo", FORMAT="JSON", CONF_KEY="template_config", TYPE="sql");
|
|
|
```
|
|
|
|
|
|
The configuration keys "template_config" will be used.
|
|
|
-
|