Fakultas Ilmu Komputer UI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hackernews Clone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Muhammad Zaki
Hackernews Clone
Commits
2c45049d
Commit
2c45049d
authored
2 years ago
by
Muhammad Zaki
Browse files
Options
Downloads
Patches
Plain Diff
refactor: open caqti module on query and mutation
parent
d7a17057
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/server.ml
+5
-3
5 additions, 3 deletions
server/server.ml
with
5 additions
and
3 deletions
server/server.ml
+
5
−
3
View file @
2c45049d
module
type
DB
=
Caqti_lwt
.
CONNECTION
module
T
=
Caqti_type
open
Caqti_request
.
Infix
let
getenv_with_default
key
fallback
=
Option
.
value
(
Sys
.
getenv_opt
key
)
~
default
:
fallback
...
...
@@ -16,13 +14,17 @@ let setup_sql_database =
postgres_host
postgres_db
)
let
list_comments
=
let
query
=
(
T
.
unit
->*
T
.(
tup2
int
string
))
"SELECT id, text FROM comment"
in
let
query
=
let
open
Caqti_request
.
Infix
in
(
T
.
unit
->*
T
.(
tup2
int
string
))
"SELECT id, text FROM comment"
in
fun
(
module
Db
:
DB
)
->
let
%
lwt
comments_or_error
=
Db
.
collect_list
query
()
in
Caqti_lwt
.
or_fail
comments_or_error
let
add_comment
=
let
mutation
=
let
open
Caqti_request
.
Infix
in
(
T
.
string
->.
T
.
unit
)
"INSERT INTO comment (text) VALUES ($1)"
in
fun
text
(
module
Db
:
DB
)
->
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment