Rust 实现的简易 SQL 数据库系统
https://www.rust-lang.org/tools/
cd sqlprimer/src/bin/
cargo run --bin server
cargo run --bin client
sqldb>> create table t1 (a int primary key, b text, c float);
CREATE TABLE t1
sqldb>> insert into t1 values (1, 'aa', 3.1), (2, 'cc', 5.3);
INSERT 2 rows
sqldb>> select * from t1;
a |b |c
--+---+----
1 |AA |3.1
2 |CC |5.3
(2 rows)
create table:
CREATE TABLE table_name (
[ column_name data_type [index] [ column_constraint [...] ] ]
[, ... ]
);
where data_type is:
- BOOLEAN(BOOL): true | false
- FLOAT(DOUBLE)
- INTEGER(INT)
- STRING(TEXT, VARCHAR)
where column_constraint is:
[ NOT NULL | NULL | DEFAULT expr ]
drop table:
DROP TABLE table_name;
INSERT INTO table_name
[ ( column_name [, ...] ) ]
values ( expr [, ...] );
SELECT [* | col_name | function [ [ AS ] output_name [, ...] ]]
FROM from_item
[GROUP BY col_name]
[ORDER BY col_name [asc | desc] [, ...]]
[LIMIT count]
[OFFSET count]
where function
is:
- count(col_name)
- min(col_name)
- max(col_name)
- sum(col_name)
- avg(col_name)
where from_item
is:
- table_name
- table_name
join_type
table_name [ON
predicate]
where join_type
is:
- cross join
- join
- left join
- right join
where on predicate
is:
- column_name = column_name
UPDATE table_name
SET column_name = expr [, ...]
[WHERE condition];
where condition is: column_name = expr
DELETE FROM table_name
[WHERE condition];
where condition is: column_name = expr
SHOW TABLES;
SHOW TABLE `table_name`;
BEGIN;
COMMIT;
ROLLBACK;
explain sql;