Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 committed Feb 3, 2024
1 parent b7ffdcd commit 6e25101
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,34 @@ See the [API documentation](https://ose-net.github.io/yesql.net/api/YeSql.Net.ht

Create a file with **.sql** extension containing the SQL statements.

**Example:**
> It is recommended that the **extension be lowercase** so that there are no problems when loading the SQL file on a Linux distro.
**Example:** `users.sql`
```sql
-- name: GetUsers
-- Gets user information.
-- Gets all users
SELECT
id,
username,
email
FROM users;

-- name: GetRoles
-- Gets role information.
-- name: GetUserById
-- Gets user information
SELECT
id,
name
FROM roles;
id,
username,
email
FROM users
WHERE id = @id;

-- name: InsertUser
-- Create user record
INSERT INTO users (id, username, email)
VALUES (@id, @username, @email);
```
Each SQL statement must be associated with a tag using the `name:` prefix and must begin with a comment. This is necessary so that the parser can uniquely identify each SQL statement by its tag.

For example, in this case the tag is `GetRoles` and the SQL statement would be `SELECT id, name FROM roles;`.
For example, in this case the tag is `GetUsers` and the SQL statement would be `SELECT id, email FROM users;`.

You should also note that comments that do not use the `name:` prefix will be ignored by the parser.

Expand Down Expand Up @@ -120,6 +128,8 @@ string sqlCode = sqlStatements[tagName];
```
But you must specify the tag name to access the SQL statement. Remember that each SQL code is identified with its respective tag.

> The tag name is case-sensitive. `GetUsers` is not the same as `getUsers`.
### Load from a set of directories

You can load SQL statements from all the SQL files in the specified directories.
Expand Down

0 comments on commit 6e25101

Please sign in to comment.