Sqlparser
Simple SQL parser meant for querying CSV files
Install / Use
/learn @marianogappa/SqlparserREADME
sqlparser - meant for querying csv files
Usage
package main
import (
"fmt"
"log"
"github.com/marianogappa/sqlparser"
)
func main() {
query, err := sqlparser.Parse("SELECT a, b, c FROM 'd' WHERE e = '1' AND f > '2'")
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+#v", query)
}
Example: SELECT works
query, err := sqlparser.Parse(`SELECT a FROM 'b'`)
query.Query {
Type: Select
TableName: b
Conditions: []
Updates: map[]
Inserts: []
Fields: [a]
Aliases: map[]
}
Example: SELECT works with lowercase
query, err := sqlparser.Parse(`select a fRoM 'b'`)
query.Query {
Type: Select
TableName: b
Conditions: []
Updates: map[]
Inserts: []
Fields: [a]
Aliases: map[]
}
Example: SELECT many fields works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b'`)
query.Query {
Type: Select
TableName: b
Conditions: []
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT with alias works
query, err := sqlparser.Parse(`SELECT a as z, b as y, c FROM 'b'`)
query.Query {
Type: Select
TableName: b
Conditions: []
Updates: map[]
Inserts: []
Fields: [a b c]
Aliases: map[a:z b:y]
}
Example: SELECT with WHERE with = works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a = ''`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Eq,
Operand2: ,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT with WHERE with < works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a < '1'`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Lt,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT with WHERE with <= works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a <= '1'`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Lte,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT with WHERE with > works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a > '1'`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Gt,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT with WHERE with >= works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a >= '1'`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Gte,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT with WHERE with != works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a != '1'`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Ne,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT with WHERE with != works (comparing field against another field)
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a != b`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Ne,
Operand2: b,
Operand2IsField: true,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: SELECT * works
query, err := sqlparser.Parse(`SELECT * FROM 'b'`)
query.Query {
Type: Select
TableName: b
Conditions: []
Updates: map[]
Inserts: []
Fields: [*]
Aliases: map[]
}
Example: SELECT a, * works
query, err := sqlparser.Parse(`SELECT a, * FROM 'b'`)
query.Query {
Type: Select
TableName: b
Conditions: []
Updates: map[]
Inserts: []
Fields: [a *]
Aliases: map[]
}
Example: SELECT with WHERE with two conditions using AND works
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a != '1' AND b = '2'`)
query.Query {
Type: Select
TableName: b
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Ne,
Operand2: 1,
Operand2IsField: false,
}
{
Operand1: b,
Operand1IsField: true,
Operator: Eq,
Operand2: 2,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: [a c d]
Aliases: map[]
}
Example: UPDATE works
query, err := sqlparser.Parse(`UPDATE 'a' SET b = 'hello' WHERE a = '1'`)
query.Query {
Type: Update
TableName: a
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Eq,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[b:hello]
Inserts: []
Fields: []
Aliases: map[]
}
Example: UPDATE works with simple quote inside
query, err := sqlparser.Parse(`UPDATE 'a' SET b = 'hello\'world' WHERE a = '1'`)
query.Query {
Type: Update
TableName: a
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Eq,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[b:hello\'world]
Inserts: []
Fields: []
Aliases: map[]
}
Example: UPDATE with multiple SETs works
query, err := sqlparser.Parse(`UPDATE 'a' SET b = 'hello', c = 'bye' WHERE a = '1'`)
query.Query {
Type: Update
TableName: a
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Eq,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[b:hello c:bye]
Inserts: []
Fields: []
Aliases: map[]
}
Example: UPDATE with multiple SETs and multiple conditions works
query, err := sqlparser.Parse(`UPDATE 'a' SET b = 'hello', c = 'bye' WHERE a = '1' AND b = '789'`)
query.Query {
Type: Update
TableName: a
Conditions: [
{
Operand1: a,
Operand1IsField: true,
Operator: Eq,
Operand2: 1,
Operand2IsField: false,
}
{
Operand1: b,
Operand1IsField: true,
Operator: Eq,
Operand2: 789,
Operand2IsField: false,
}]
Updates: map[b:hello c:bye]
Inserts: []
Fields: []
Aliases: map[]
}
Example: DELETE with WHERE works
query, err := sqlparser.Parse(`DELETE FROM 'a' WHERE b = '1'`)
query.Query {
Type: Delete
TableName: a
Conditions: [
{
Operand1: b,
Operand1IsField: true,
Operator: Eq,
Operand2: 1,
Operand2IsField: false,
}]
Updates: map[]
Inserts: []
Fields: []
Aliases: map[]
}
Example: INSERT works
query, err := sqlparser.Parse(`INSERT INTO 'a' (b) VALUES ('1')`)
query.Query {
Type: Insert
TableName: a
Conditions: []
Updates: map[]
Inserts: [[1]]
Fields: [b]
Aliases: map[]
}
Example: INSERT with multiple fields works
query, err := sqlparser.Parse(`INSERT INTO 'a' (b,c, d) VALUES ('1','2' , '3' )`)
query.Query {
Type: Insert
TableName: a
Conditions: []
Updates: map[]
Inserts: [[1 2 3]]
Fields: [b c d]
Aliases: map[]
}
Example: INSERT with multiple fields and multiple values works
query, err := sqlparser.Parse(`INSERT INTO 'a' (b,c, d) VALUES ('1','2' , '3' ),('4','5' ,'6' )`)
query.Query {
Type: Insert
TableName: a
Conditions: []
Updates: map[]
Inserts: [[1 2 3] [4 5 6]]
Fields: [b c d]
Aliases: map[]
}
Example: empty query fails
query, err := sqlparser.Parse(``)
query type cannot be empty
Example: SELECT without FROM fails
query, err := sqlparser.Parse(`SELECT`)
table name cannot be empty
Example: SELECT without fields fails
query, err := sqlparser.Parse(`SELECT FROM 'a'`)
at SELECT: expected field to SELECT
Example: SELECT with comma and empty field fails
query, err := sqlparser.Parse(`SELECT b, FROM 'a'`)
at SELECT: expected field to SELECT
Example: SELECT with empty WHERE fails
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE`)
at WHERE: empty WHERE clause
Example: SELECT with WHERE with only operand fails
query, err := sqlparser.Parse(`SELECT a, c, d FROM 'b' WHERE a`)
at WHERE: condition without operator
Example: Empty UPDATE fails
query, err := sqlparser.Parse(`UPDATE`)
table name cannot be empty
Related Skills
oracle
339.3kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
prose
339.3kOpenProse VM skill pack. Activate on any `prose` command, .prose files, or OpenProse mentions; orchestrates multi-agent workflows.
Command Development
83.9kThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
Plugin Structure
83.9kThis skill should be used when the user asks to "create a plugin", "scaffold a plugin", "understand plugin structure", "organize plugin components", "set up plugin.json", "use ${CLAUDE_PLUGIN_ROOT}", "add commands/agents/skills/hooks", "configure auto-discovery", or needs guidance on plugin directory layout, manifest configuration, component organization, file naming conventions, or Claude Code plugin architecture best practices.
