Code Monkey home page Code Monkey logo

Comments (4)

nwronski avatar nwronski commented on June 25, 2024

Another great find! This is probably an oversight on my part. I will make this change and tag this issue with the fix.

from sqlite-parser.

nwronski avatar nwronski commented on June 25, 2024

@jdrew1303 What do you think about the following?

  • variant when has a condition and a consequent
  • variant else has just a consequent
  • the outer expression is now variant case instead of binary
  • instead of taking whatever is provided between CASE and WHEN (e.g., CASE foo WHEN ...) and calling that the expression, it is now added as the discriminant
select
    case acc
      when a = 0 then a1
      when a = 1 then b1
      else c1
    end

CASE Statement AST

{
  "type": "expression",
  "variant": "case",
  "expression": [
    {
      "type": "condition",
      "variant": "when",
      "condition": {
        "type": "expression",
        "format": "binary",
        "variant": "operation",
        "operation": "=",
        "left": {
          "type": "identifier",
          "variant": "column",
          "name": "a"
        },
        "right": {
          "type": "literal",
          "variant": "decimal",
          "value": "0"
        }
      },
      "consequent": {
        "type": "identifier",
        "variant": "column",
        "name": "a1"
      }
    },
    {
      "type": "condition",
      "variant": "when",
      "condition": {
        "type": "expression",
        "format": "binary",
        "variant": "operation",
        "operation": "=",
        "left": {
          "type": "identifier",
          "variant": "column",
          "name": "a"
        },
        "right": {
          "type": "literal",
          "variant": "decimal",
          "value": "1"
        }
      },
      "consequent": {
        "type": "identifier",
        "variant": "column",
        "name": "b1"
      }
    },
    {
      "type": "condition",
      "variant": "else",
      "consequent": {
        "type": "identifier",
        "variant": "column",
        "name": "c1"
      }
    }
  ],
  "discriminant": {
    "type": "identifier",
    "variant": "column",
    "name": "acc"
  }
}

from sqlite-parser.

nwronski avatar nwronski commented on June 25, 2024

Included in latest sqlite-parser@beta release v1.0.0-rc2.

from sqlite-parser.

jdrew1303 avatar jdrew1303 commented on June 25, 2024

Looks good to me 👍 The new changes are working like a charm. :)

from sqlite-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.