-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery_sql.rb
77 lines (63 loc) · 1.62 KB
/
query_sql.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# auto-generated by sqlc - do not edit
require 'connection_pool'
require 'sqlite3'
module Sqlite3Codegen
GetAuthorSql = %q(SELECT id, name, bio FROM authors
WHERE id = ? LIMIT 1)
class GetAuthorRow < Data.define(:id, :name, :bio)
end
class GetAuthorArgs < Data.define(:id)
end
ListAuthorsSql = %q(SELECT id, name, bio FROM authors
ORDER BY name)
class ListAuthorsRow < Data.define(:id, :name, :bio)
end
CreateAuthorSql = %q(INSERT INTO authors (
name, bio
) VALUES (
?, ?
))
class CreateAuthorArgs < Data.define(:name, :bio)
end
DeleteAuthorSql = %q(DELETE FROM authors
WHERE id = ?)
class DeleteAuthorArgs < Data.define(:id)
end
class QuerySql
def initialize(db)
@db = db
end
def get_author(get_author_args)
client = @db
query_params = [get_author_args.id]
stmt = client.prepare(GetAuthorSql)
result = stmt.execute(*query_params)
row = result.first
return nil if row.nil?
entity = GetAuthorRow.new(row[0], row[1], row[2])
return entity
end
def list_authors
client = @db
stmt = client.prepare(ListAuthorsSql)
result = stmt.execute
entities = []
result.each do |row|
entities << ListAuthorsRow.new(row[0], row[1], row[2])
end
return entities
end
def create_author(create_author_args)
client = @db
query_params = [create_author_args.name, create_author_args.bio]
stmt = client.prepare(CreateAuthorSql)
stmt.execute(*query_params)
end
def delete_author(delete_author_args)
client = @db
query_params = [delete_author_args.id]
stmt = client.prepare(DeleteAuthorSql)
stmt.execute(*query_params)
end
end
end