File tree 6 files changed +50
-4
lines changed
6 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -615,6 +615,10 @@ queries.
615
615
(~> (from ,table #:as t)
616
616
(where (= (fragment (ast:qualified "t " column)) "bogdan " )))))
617
617
]
618
+
619
+ @history[
620
+ #:changed "0.15 " @elem{Added support for string fragments.}
621
+ ]
618
622
}
619
623
@defop[ilike (display (select _ (ilike "A " "%a% " )))]
620
624
@defop[in (display (select _ (in 5 '(1 2 3 4 5 ))))]
Original file line number Diff line number Diff line change 1
1
#lang info
2
2
3
3
(define license 'BSD-3-Clause )
4
- (define version "0.14 " )
4
+ (define version "0.15 " )
5
5
(define collection "deta " )
6
6
7
7
(define deps '("base "
Original file line number Diff line number Diff line change 25
25
expr?
26
26
expr-terminal?
27
27
28
+ make-fragment
28
29
(struct-out app)
29
30
(struct-out as)
30
31
(struct-out case-e)
31
32
(struct-out column)
33
+ (struct-out fragment)
32
34
(struct-out ident)
33
35
(struct-out placeholder)
34
36
(struct-out qualified)
54
56
(struct column expr (e)
55
57
#:transparent )
56
58
59
+ (struct fragment expr (e)
60
+ #:transparent )
61
+
57
62
(struct ident expr (name)
58
63
#:transparent )
59
64
72
77
(struct table expr (e)
73
78
#:transparent )
74
79
80
+ (define (make-fragment e)
81
+ (cond
82
+ [(string? e) (fragment e)]
83
+ [(expr? e) e]
84
+ [else (raise-argument-error 'fragment "(or/c string? expr?) " e)]))
85
+
75
86
76
87
;; clauses ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77
88
Original file line number Diff line number Diff line change 64
64
[(table e) (write-expr e)]
65
65
[(column e) (write-expr e)]
66
66
67
+ [(fragment s)
68
+ (write-string s)]
69
+
67
70
[(ident i)
68
71
(write-string (ident->string i))]
69
72
Original file line number Diff line number Diff line change 360
360
361
361
(define-syntax-class fragment-expr
362
362
#:literals (fragment)
363
- (pattern (fragment node:expr) #:with e #'node ))
363
+ (pattern (fragment node:expr)
364
+ #:with e #'(ast:make-fragment node)))
364
365
365
366
(define-syntax-class subquery-expr
366
367
#:literals (subquery)
Original file line number Diff line number Diff line change 2
2
3
3
(require db
4
4
deta
5
+ (prefix-in ast: deta/private/ast)
5
6
deta/private/meta
6
7
gregor
7
8
racket/match
318
319
319
320
(check-true (null? all-active-users))
320
321
321
- (match-define (list active -user-jim active-user-bob)
322
+ (match-define (list _active -user-jim active-user-bob)
322
323
(insert! (current-conn)
323
324
(make-user
#:username "[email protected] "
324
325
#:active? #t )
422
423
(test-case "can fail to look up entities "
423
424
(check-false (lookup (current-conn)
424
425
(~> (from user #:as u)
425
- (where #f )))))))))
426
+ (where #f ))))))
427
+
428
+ (test-suite
429
+ "fragment "
430
+
431
+ (test-case "fragment with ast nodes "
432
+ (check-equal?
433
+ (with-output-to-string
434
+ (lambda ()
435
+ (display
436
+ (~> (from user #:as u)
437
+ (select u.name)
438
+ (where (fragment (ast:app
439
+ (ast:ident '= )
440
+ (list (ast:qualified "u " "name " )
441
+ (ast:scalar "Bogdan " )))))))))
442
+ "#<query: SELECT u.name FROM users AS u WHERE u.name = 'Bogdan'> " ))
443
+
444
+ (test-case "fragment with string "
445
+ (check-equal?
446
+ (with-output-to-string
447
+ (lambda ()
448
+ (display
449
+ (~> (from user #:as u)
450
+ (select u.name)
451
+ (where (fragment "u.name = 'Bogdan' " ))))))
452
+ "#<query: SELECT u.name FROM users AS u WHERE u.name = 'Bogdan'> " ))))))
426
453
427
454
(module+ test
428
455
(require rackunit/text-ui)
You can’t perform that action at this time.
0 commit comments