https://github.com/vegarsti/sql
a SQL interpreter
https://github.com/vegarsti/sql
db dbms go golang interpreter sql
Last synced: 11 months ago
JSON representation
a SQL interpreter
- Host: GitHub
- URL: https://github.com/vegarsti/sql
- Owner: vegarsti
- Created: 2021-07-16T19:12:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-26T20:04:16.000Z (over 4 years ago)
- Last Synced: 2025-04-25T05:54:00.676Z (11 months ago)
- Topics: db, dbms, go, golang, interpreter, sql
- Language: Go
- Homepage:
- Size: 247 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sql
[](https://goreportcard.com/report/github.com/vegarsti/sql)
The interpreter can be run interactively.
```
$ go run cmd/sql/main.go
>> create table programming_languages (name text, first_appeared integer);
OK
>> insert into programming_languages values ('C', 1972), ('Python', 1990), ('Lisp', 1958), ('Go', 2009)
OK
>> select name, first_appeared from programming_languages where first_appeared < 2000 order by first_appeared
name first_appeared
'Lisp' 1958
'C' 1972
'Python' 1990
>> select 1, 3.14 as pi, '✅' as emoji, 'Vegard' as name
1 pi emoji name
1 3.140000 '✅' 'Vegard'
>> create table squares (number int, square int)
OK
>> insert into squares values (1, 1), (2, 2^2), (3, 3^2)
OK
>> create table cubes (number int, cube int)
OK
>> insert into cubes values (1, 1), (2, 2^3), (3, 3^3)
OK
>> select s.number, square, cube from squares s join cubes c on s.number = c.number
number square cube
1 1 1
2 4 8
3 9 27
```
The interpreter also supports running against standard input.
```
$ cat example.sql | go run cmd/sql/main.go
name first_appeared
'C' 1972
'Python' 1990
'Lisp' 1958
'Go' 2009
```
Based on Thorsten Ball's excellent [Writing an Interpreter in Go](https://interpreterbook.com/).