1.1.0-alpha.0 • Published 2 years ago

ymlr-sql v1.1.0-alpha.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

ymlr-sql

ymlr-sql for ymlr plugin

Shares

Tag details

TagsDescription
ymlr-sqlDeclare a sql connector.

Supported drivers:

ymlr-sql

Declare a sql connector. Supported drivers:

Example:

  - name: "[sql] localhost"
    ymlr-sql:
      uri: mysql://user:pass@ip:port          # mysql uri
      opts:                                   # Refs: https://knexjs.org/guide/#configuration-options
        client: mysql                         # See the drivers in "ymlr-sql"
      runs:                                   # Execute the below commands after connected
        - echo: sql is connected

Execute a query

  - name: "[sql] localhost"
    ymlr-sql:
      uri: postgresql://user:pass@ip:port     # postgresql uri
      runs:                                   # Execute the below commands after connected
        - js: |
            $vars.result = await this.$parentState.sqlCtx.raw('SELECT * FROM Table WHERE id = ? and type = ?', 1, 'my-type')
        - echo: ${ $vars.result }

ymlr-sql'query

Execute a sql query Supported drivers:

Example:

Publish a message to sql

  - name: "[sql] localhost"
    ymlr-sql'query:
      uri: postgresql://user:pass@ip:port                     # postgresql uri
      opts:
        client: pg
      query: "SELECT * FROM Table WHERE id = ? and type = ?"
      prms:
        - 1
        - my-type
    vars: result

  - echo: ${ $vars.result }

Reuse sql connection to execute multiple times

  - name: "[sql] localhost"
    ymlr-sql:
      uri: postgresql://user:pass@ip:port                     # postgresql uri
      opts:
        client: pg
      runs:
        - ymlr-sql'query:
            query: "SELECT * FROM Table WHERE id = ? and type = ?"
            prms:
              - 1
              - my-type
        - ...
        # Other elements

Or reuse by global variable Reuse sql connection to execute multiple times

  - name: "[sql] localhost"
    id: db
    ymlr-sql:
      uri: postgresql://user:pass@ip:port                     # postgresql uri
      opts:
        client: pg

  - ymlr-sql'query:
      sql: ${ $vars.db }
      query: "SELECT * FROM Table WHERE id = ? and type = ?"
      prms:
        - 1
        - my-type
  - ...
  # Other elements

Have fun :)