Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: More SQL Syntax Support for SQLite #1687

Merged
merged 24 commits into from
Jun 18, 2022

Conversation

hakobera
Copy link
Contributor

@hakobera hakobera commented Jun 17, 2022

This pull request includes multiple SQL Syntax supports for SQLite for #161

Features

  • SELECT
    • Support WHERE, GROUP BY, HAVING, LIMIT, OFFSET
    • Support nested SELECT like select_nested_count
  • INSERT
    • Support both values and SELECT insert
  • UPDATE
    • Support simple update set
  • DDL
    • Support CREATE VIEW and DROP VIEW
    • Support bool type
  • Function
    • coalesce function

Examples

  • authors
  • booktest
  • ondeck

Also add endtoend test data as much as possible.

Breaking Change

  • numeric and decimal are mapped to float64 (currently these are mapped to int64

hakobera added 23 commits June 6, 2022 20:26
* Add support `where` and `join` clause
* Add support table alias
* column_as
* comment_syntax
* comparisons
* create_view
* identical_tables
* inflection
* insert_select
* insert_select_invalid
* insert_values
* support `GROUP BY` and `HAVING`
* support `ORDER BY`
* support wildcard(`*`) column with table name
* invalid_group_by_reference
* invalid_table_alias
* join_alias
* join_from
* join_left
* join_left_same_table
* join_table_name
* join_two_tables
* join_where_clause
* limit
* limit_offset
    * select_limit
    * limit_offset
    * single_param_conflict
    * update_set
    * update_set_multiple
@hakobera hakobera changed the title More SQL Syntax Support for SQLite. feat: More SQL Syntax Support for SQLite. Jun 17, 2022
@hakobera hakobera changed the title feat: More SQL Syntax Support for SQLite. feat: More SQL Syntax Support for SQLite Jun 17, 2022
@russellhaering
Copy link

This looks awesome, let me test a little bit but I'm definitely inclined to close out #1686 in favor of this.

@DBarney
Copy link

DBarney commented Jun 17, 2022

Wow, yeah lets go with this. I just got the Update statement working on my local branch after some work this morning, but this covers all that and more. So nice work @hakobera!

@russellhaering
Copy link

Ran this against my (still pretty minimal) codebase and results look great. Its generating identical code for SELECT compared to #1686, identical code for INSERT compared to #1653, plus is generating correct-looking code for UPDATEs which I didn't have a solution for yet.

Closed my PR in favor of this.

@hakobera hakobera mentioned this pull request Jun 18, 2022
@kyleconroy kyleconroy merged commit 0dc2c81 into sqlc-dev:main Jun 18, 2022
@hakobera hakobera deleted the add-simple-crud-support-for-sqlite branch June 19, 2022 08:26
@javiercbk
Copy link
Contributor

javiercbk commented Jun 21, 2022

I executed some tests over a small project and it works!!!.

Unrelated to this PR, but I'll try to fix this small issue

-- name: Insert :exec
INSERT INTO users (uuid, email, phone) VALUES (?, ?, ?);

Generated Go code

func (q *Queries) Insert(ctx context.Context, arg InsertParams) error {
	_, err := q.db.ExecContext(ctx, insert, arg.Uuid, arg.Email, arg.Phone)
	return err
}

Better

func (q *Queries) Insert(ctx context.Context, arg InsertParams) (int64, error) {
	result, err := q.db.ExecContext(ctx, insert, arg.Uuid, arg.Email, arg.Phone)
	if err != nil {
		return 0, err
	}
	return result.LastInsertId()
}

EDIT:

The correct way to do this is

-- name: Insert :execresult
INSERT INTO users (uuid, email, phone) VALUES (?, ?, ?);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants