forked from datastax/php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_string_queries.feature
142 lines (125 loc) · 4.7 KB
/
simple_string_queries.feature
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Feature: Simple string queries
PHP Driver supports running string queries.
Background:
Given a running Cassandra cluster
And the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TABLE playlists (
id uuid,
title text,
album text,
artist text,
song_id uuid,
PRIMARY KEY (id, title, album, artist)
);
INSERT INTO playlists
(id, song_id, artist, title, album) VALUES
(62c36092-82a1-3a00-93d1-46196ee77204, 756716f7-2e54-4715-9f00-91dcbea6cf50, 'Joséphine Baker', 'La Petite Tonkinoise', 'Bye Bye Blackbird');
INSERT INTO playlists
(id, song_id, artist, title, album) VALUES
(62c36092-82a1-3a00-93d1-46196ee77204, f6071e72-48ec-4fcb-bf3e-379c8a696488, 'Willi Ostermann', 'Die Mösch', 'In Gold');
INSERT INTO playlists
(id, song_id, artist, title, album) VALUES
(62c36092-82a1-3a00-93d1-46196ee77204, fbdf82ed-0063-4796-9c7c-a3d4f47b4b25, 'Mick Jager', 'Memo From Turner', 'Performance');
"""
Scenario: A simple CQL string can be used to execute queries
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$result = $session->execute("SELECT * FROM playlists");
foreach ($result as $row) {
echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . PHP_EOL;
}
"""
When it is executed
Then its output should contain:
"""
Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
"""
And its output should contain:
"""
Willi Ostermann: Die Mösch / In Gold
"""
And its output should contain:
"""
Mick Jager: Memo From Turner / Performance
"""
Scenario: A simple CQL string can also be used to execute asynchronous queries
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$future = $session->executeAsync("SELECT * FROM playlists");
echo "Doing something else..." . PHP_EOL;
$result = $future->get();
foreach ($result as $row) {
echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . PHP_EOL;
}
"""
When it is executed
Then its output should contain:
"""
Doing something else...
"""
And its output should contain:
"""
Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
"""
And its output should contain:
"""
Willi Ostermann: Die Mösch / In Gold
"""
And its output should contain:
"""
Mick Jager: Memo From Turner / Performance
"""
Scenario: Simple CQL strings can also be used in batch statements
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$future = $session->executeAsync("SELECT * FROM playlists");
$batch = new Cassandra\BatchStatement(Cassandra::BATCH_UNLOGGED);
$batch->add("INSERT INTO playlists
(id, song_id, artist, title, album) VALUES
(3a55adfc-bbf6-43bd-9428-e714f109b977, 82a954c4-750a-4ada-8e02-6b15c9bf3140 , 'The Beatles', 'Come Together', 'Abbey Road')");
$batch->add("INSERT INTO playlists
(id, song_id, artist, title, album) VALUES
(3a55adfc-bbf6-43bd-9428-e714f109b977, 564e3c0d-bc3b-4d2d-8a34-679bb5247b71, 'Michael Jackson', 'Thriller', 'Thriller')");
$batch->add("INSERT INTO playlists
(id, song_id, artist, title, album) VALUES
(3a55adfc-bbf6-43bd-9428-e714f109b977, 326ead7f-4c54-43f4-9b1b-40f7ca84cd5e, 'Pink Floyd', 'Another Brick in the Wall (Part I)', 'The Wall')");
$session->execute($batch);
$result = $session->execute("SELECT * FROM playlists");
foreach ($result as $row) {
echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . PHP_EOL;
}
"""
When it is executed
Then its output should contain:
"""
The Beatles: Come Together / Abbey Road
"""
And its output should contain:
"""
Michael Jackson: Thriller / Thriller
"""
And its output should contain:
"""
Pink Floyd: Another Brick in the Wall (Part I) / The Wall
"""