Skip to content

Commit 5f367f1

Browse files
committed
Reformat every SQL query
rustfmt f44d906 kinda messed up alignment of every sql query
1 parent 9415221 commit 5f367f1

File tree

9 files changed

+263
-242
lines changed

9 files changed

+263
-242
lines changed

src/db/add_package.rs

+44-26
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ pub fn add_package_into_database(conn: &Connection,
4747

4848
if rows.len() == 0 {
4949
let rows = try!(conn.query("INSERT INTO releases (
50-
crate_id, version, release_time, \
51-
dependencies, target_name, yanked, build_status, \
52-
rustdoc_status, test_status, license, repository_url, \
53-
homepage_url, description, description_long, readme, \
54-
authors, keywords, have_examples, downloads, files, \
55-
doc_targets, is_library, doc_rustc_version, \
56-
documentation_url \
57-
) \
58-
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, \
59-
$11, $12, $13, $14, $15, $16, $17, $18, $19, \
60-
$20, $21, $22, $23, $24 \
61-
) \
50+
crate_id, version, release_time,
51+
dependencies, target_name, yanked, build_status,
52+
rustdoc_status, test_status, license, repository_url,
53+
homepage_url, description, description_long, readme,
54+
authors, keywords, have_examples, downloads, files,
55+
doc_targets, is_library, doc_rustc_version,
56+
documentation_url
57+
)
58+
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10,
59+
$11, $12, $13, $14, $15, $16, $17, $18, $19,
60+
$20, $21, $22, $23, $24
61+
)
6262
RETURNING id",
6363
&[&crate_id,
6464
&format!("{}", pkg.manifest().version()),
@@ -88,13 +88,29 @@ pub fn add_package_into_database(conn: &Connection,
8888
rows.get(0).get(0)
8989

9090
} else {
91-
try!(conn.query("UPDATE releases SET release_time = $3, dependencies = $4, \
92-
target_name = $5, yanked = $6, build_status = $7, rustdoc_status = \
93-
$8, test_status = $9, license = $10, repository_url = $11, \
94-
homepage_url = $12, description = $13, description_long = $14, \
95-
readme = $15, authors = $16, keywords = $17, have_examples = $18, \
96-
downloads = $19, files = $20, doc_targets = $21, is_library = $22, \
97-
doc_rustc_version = $23, documentation_url = $24 \
91+
try!(conn.query("UPDATE releases
92+
SET release_time = $3,
93+
dependencies = $4,
94+
target_name = $5,
95+
yanked = $6,
96+
build_status = $7,
97+
rustdoc_status = $8,
98+
test_status = $9,
99+
license = $10,
100+
repository_url = $11,
101+
homepage_url = $12,
102+
description = $13,
103+
description_long = $14,
104+
readme = $15,
105+
authors = $16,
106+
keywords = $17,
107+
have_examples = $18,
108+
downloads = $19,
109+
files = $20,
110+
doc_targets = $21,
111+
is_library = $22,
112+
doc_rustc_version = $23,
113+
documentation_url = $24
98114
WHERE crate_id = $1 AND version = $2",
99115
&[&crate_id,
100116
&format!("{}", pkg.manifest().version()),
@@ -162,10 +178,11 @@ pub fn add_build_into_database(conn: &Connection,
162178
res: &ChrootBuilderResult)
163179
-> Result<i32> {
164180
debug!("Adding build into database");
165-
let rows = try!(conn.query("INSERT INTO builds (rid, rustc_version, cratesfyi_version, \
166-
build_status, output)
167-
VALUES \
168-
($1, $2, $3, $4, $5) RETURNING id",
181+
let rows = try!(conn.query("INSERT INTO builds (rid, rustc_version,
182+
cratesfyi_version,
183+
build_status, output)
184+
VALUES ($1, $2, $3, $4, $5)
185+
RETURNING id",
169186
&[release_id,
170187
&res.rustc_version,
171188
&res.cratesfyi_version,
@@ -343,7 +360,7 @@ fn add_authors_into_database(conn: &Connection, pkg: &Package, release_id: &i32)
343360
if rows.len() > 0 {
344361
rows.get(0).get(0)
345362
} else {
346-
try!(conn.query("INSERT INTO authors (name, email, slug) VALUES ($1, $2, $3) \
363+
try!(conn.query("INSERT INTO authors (name, email, slug) VALUES ($1, $2, $3)
347364
RETURNING id",
348365
&[&author, &email, &slug]))
349366
.get(0)
@@ -408,8 +425,9 @@ fn add_owners_into_database(conn: &Connection, pkg: &Package, crate_id: &i32) ->
408425
if rows.len() > 0 {
409426
rows.get(0).get(0)
410427
} else {
411-
try!(conn.query("INSERT INTO owners (login, avatar, name, email) VALUES ($1, \
412-
$2, $3, $4) RETURNING id",
428+
try!(conn.query("INSERT INTO owners (login, avatar, name, email)
429+
VALUES ($1, $2, $3, $4)
430+
RETURNING id",
413431
&[&login, &avatar, &name, &email]))
414432
.get(0)
415433
.get(0)

src/db/mod.rs

+103-103
Original file line numberDiff line numberDiff line change
@@ -72,111 +72,111 @@ pub fn update_search_index(conn: &Connection) -> Result<u64, Error> {
7272

7373
/// Creates database tables
7474
pub fn create_tables(conn: &Connection) -> Result<(), Error> {
75-
let queries = ["CREATE TABLE crates ( \
76-
id SERIAL PRIMARY KEY, \
77-
name VARCHAR(255) UNIQUE NOT NULL, \
78-
latest_version_id INT DEFAULT 0, \
79-
versions JSON DEFAULT '[]', \
80-
downloads_total INT DEFAULT 0, \
81-
github_description VARCHAR(1024), \
82-
github_stars INT DEFAULT 0, \
83-
github_forks INT DEFAULT 0, \
84-
github_issues INT DEFAULT 0, \
85-
github_last_commit TIMESTAMP, \
86-
github_last_update TIMESTAMP, \
87-
content tsvector \
88-
)",
89-
"CREATE TABLE releases ( \
90-
id SERIAL PRIMARY KEY, \
91-
crate_id INT NOT NULL REFERENCES crates(id), \
92-
version VARCHAR(100), \
93-
release_time TIMESTAMP, \
94-
dependencies JSON, \
95-
target_name VARCHAR(255), \
96-
yanked BOOL DEFAULT FALSE, \
97-
is_library BOOL DEFAULT TRUE, \
98-
build_status BOOL DEFAULT FALSE, \
99-
rustdoc_status BOOL DEFAULT FALSE, \
100-
test_status BOOL DEFAULT FALSE, \
101-
license VARCHAR(100), \
102-
repository_url VARCHAR(255), \
103-
homepage_url VARCHAR(255), \
104-
documentation_url VARCHAR(255), \
105-
description VARCHAR(1024), \
106-
description_long VARCHAR(51200), \
107-
readme VARCHAR(51200), \
108-
authors JSON, \
109-
keywords JSON, \
110-
have_examples BOOL DEFAULT FALSE, \
111-
downloads INT DEFAULT 0, \
112-
files JSON, \
113-
doc_targets JSON DEFAULT '[]', \
114-
doc_rustc_version VARCHAR(100) NOT NULL, \
115-
UNIQUE (crate_id, version) \
116-
)",
117-
"CREATE TABLE authors ( \
118-
id SERIAL PRIMARY KEY, \
119-
name VARCHAR(255), \
120-
email VARCHAR(255), \
121-
slug VARCHAR(255) UNIQUE NOT NULL \
122-
)",
123-
"CREATE TABLE author_rels ( \
124-
rid INT REFERENCES releases(id), \
125-
aid INT REFERENCES authors(id), \
126-
UNIQUE(rid, aid) \
127-
)",
128-
"CREATE TABLE keywords ( \
129-
id SERIAL PRIMARY KEY, \
130-
name VARCHAR(255), \
131-
slug VARCHAR(255) NOT NULL UNIQUE \
132-
)",
133-
"CREATE TABLE keyword_rels ( \
134-
rid INT REFERENCES releases(id), \
135-
kid INT REFERENCES keywords(id), \
136-
UNIQUE(rid, kid) \
137-
)",
138-
"CREATE TABLE owners ( \
139-
id SERIAL PRIMARY KEY, \
140-
login VARCHAR(255) NOT NULL UNIQUE, \
141-
avatar VARCHAR(255), \
142-
name VARCHAR(255), \
143-
email VARCHAR(255) \
144-
)",
145-
"CREATE TABLE owner_rels ( \
146-
cid INT REFERENCES releases(id), \
147-
oid INT REFERENCES owners(id), \
148-
UNIQUE(cid, oid) \
149-
)",
150-
"CREATE TABLE builds ( \
151-
id SERIAL, \
152-
rid INT NOT NULL REFERENCES releases(id), \
153-
rustc_version VARCHAR(100) NOT NULL, \
154-
cratesfyi_version VARCHAR(100) NOT NULL, \
155-
build_status BOOL NOT NULL, \
156-
build_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, \
157-
output TEXT \
158-
)",
159-
"CREATE TABLE queue ( \
160-
id SERIAL, \
161-
name VARCHAR(255), \
162-
version VARCHAR(100), \
163-
attempt INT DEFAULT 0, \
164-
date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, \
165-
UNIQUE(name, version) \
166-
)",
167-
"CREATE TABLE files ( \
168-
path VARCHAR(4096) NOT NULL PRIMARY KEY, \
169-
mime VARCHAR(100) NOT NULL, \
170-
date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, \
171-
date_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, \
172-
content BYTEA \
173-
)",
75+
let queries = ["CREATE TABLE crates (
76+
id SERIAL PRIMARY KEY,
77+
name VARCHAR(255) UNIQUE NOT NULL,
78+
latest_version_id INT DEFAULT 0,
79+
versions JSON DEFAULT '[]',
80+
downloads_total INT DEFAULT 0,
81+
github_description VARCHAR(1024),
82+
github_stars INT DEFAULT 0,
83+
github_forks INT DEFAULT 0,
84+
github_issues INT DEFAULT 0,
85+
github_last_commit TIMESTAMP,
86+
github_last_update TIMESTAMP,
87+
content tsvector
88+
)",
89+
"CREATE TABLE releases (
90+
id SERIAL PRIMARY KEY,
91+
crate_id INT NOT NULL REFERENCES crates(id),
92+
version VARCHAR(100),
93+
release_time TIMESTAMP,
94+
dependencies JSON,
95+
target_name VARCHAR(255),
96+
yanked BOOL DEFAULT FALSE,
97+
is_library BOOL DEFAULT TRUE,
98+
build_status BOOL DEFAULT FALSE,
99+
rustdoc_status BOOL DEFAULT FALSE,
100+
test_status BOOL DEFAULT FALSE,
101+
license VARCHAR(100),
102+
repository_url VARCHAR(255),
103+
homepage_url VARCHAR(255),
104+
documentation_url VARCHAR(255),
105+
description VARCHAR(1024),
106+
description_long VARCHAR(51200),
107+
readme VARCHAR(51200),
108+
authors JSON,
109+
keywords JSON,
110+
have_examples BOOL DEFAULT FALSE,
111+
downloads INT DEFAULT 0,
112+
files JSON,
113+
doc_targets JSON DEFAULT '[]',
114+
doc_rustc_version VARCHAR(100) NOT NULL,
115+
UNIQUE (crate_id, version)
116+
)",
117+
"CREATE TABLE authors (
118+
id SERIAL PRIMARY KEY,
119+
name VARCHAR(255),
120+
email VARCHAR(255),
121+
slug VARCHAR(255) UNIQUE NOT NULL
122+
)",
123+
"CREATE TABLE author_rels (
124+
rid INT REFERENCES releases(id),
125+
aid INT REFERENCES authors(id),
126+
UNIQUE(rid, aid)
127+
)",
128+
"CREATE TABLE keywords (
129+
id SERIAL PRIMARY KEY,
130+
name VARCHAR(255),
131+
slug VARCHAR(255) NOT NULL UNIQUE
132+
)",
133+
"CREATE TABLE keyword_rels (
134+
rid INT REFERENCES releases(id),
135+
kid INT REFERENCES keywords(id),
136+
UNIQUE(rid, kid)
137+
)",
138+
"CREATE TABLE owners (
139+
id SERIAL PRIMARY KEY,
140+
login VARCHAR(255) NOT NULL UNIQUE,
141+
avatar VARCHAR(255),
142+
name VARCHAR(255),
143+
email VARCHAR(255)
144+
)",
145+
"CREATE TABLE owner_rels (
146+
cid INT REFERENCES releases(id),
147+
oid INT REFERENCES owners(id),
148+
UNIQUE(cid, oid)
149+
)",
150+
"CREATE TABLE builds (
151+
id SERIAL,
152+
rid INT NOT NULL REFERENCES releases(id),
153+
rustc_version VARCHAR(100) NOT NULL,
154+
cratesfyi_version VARCHAR(100) NOT NULL,
155+
build_status BOOL NOT NULL,
156+
build_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
157+
output TEXT
158+
)",
159+
"CREATE TABLE queue (
160+
id SERIAL,
161+
name VARCHAR(255),
162+
version VARCHAR(100),
163+
attempt INT DEFAULT 0,
164+
date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
165+
UNIQUE(name, version)
166+
)",
167+
"CREATE TABLE files (
168+
path VARCHAR(4096) NOT NULL PRIMARY KEY,
169+
mime VARCHAR(100) NOT NULL,
170+
date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
171+
date_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
172+
content BYTEA
173+
)",
174174
"CREATE INDEX ON releases (release_time DESC)",
175175
"CREATE INDEX content_idx ON crates USING gin(content)",
176-
"CREATE TABLE config ( \
177-
name VARCHAR(100) NOT NULL PRIMARY KEY, \
178-
value JSON NOT NULL \
179-
)",
176+
"CREATE TABLE config (
177+
name VARCHAR(100) NOT NULL PRIMARY KEY,
178+
value JSON NOT NULL
179+
)",
180180
"INSERT INTO config VALUES ('database_version', '1'::json)"];
181181

182182
for query in queries.into_iter() {

src/docbuilder/queue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ impl DocBuilder {
3838
pub fn build_packages_queue(&mut self) -> Result<()> {
3939
let conn = try!(connect_db());
4040

41-
for row in &try!(conn.query("SELECT id, name, version \
42-
FROM queue \
43-
WHERE attempt < 5 \
41+
for row in &try!(conn.query("SELECT id, name, version
42+
FROM queue
43+
WHERE attempt < 5
4444
ORDER BY id ASC",
4545
&[])) {
4646
let id: i32 = row.get(0);

src/utils/github_updater.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ pub fn github_updater() -> Result<()> {
2323

2424
// TODO: This query assumes repository field in Cargo.toml is
2525
// always the same across all versions of a crate
26-
for row in &try!(conn.query("SELECT DISTINCT ON (crates.name) \
27-
crates.name, \
28-
crates.id, \
29-
releases.repository_url \
30-
FROM crates \
31-
INNER JOIN releases ON releases.crate_id = crates.id \
32-
WHERE releases.repository_url ~ '^https*://github.com' AND \
33-
(crates.github_last_update < NOW() - INTERVAL '1 day' OR \
34-
crates.github_last_update IS NULL) \
26+
for row in &try!(conn.query("SELECT DISTINCT ON (crates.name)
27+
crates.name,
28+
crates.id,
29+
releases.repository_url
30+
FROM crates
31+
INNER JOIN releases ON releases.crate_id = crates.id
32+
WHERE releases.repository_url ~ '^https*://github.com' AND
33+
(crates.github_last_update < NOW() - INTERVAL '1 day' OR
34+
crates.github_last_update IS NULL)
3535
ORDER BY crates.name, releases.release_time DESC",
3636
&[])) {
3737
let crate_name: String = row.get(0);
@@ -42,10 +42,11 @@ pub fn github_updater() -> Result<()> {
4242
.ok_or("Failed to get github path".into())
4343
.and_then(|path| get_github_fields(&path[..]))
4444
.and_then(|fields| {
45-
conn.execute("UPDATE crates SET github_description = $1, \
46-
github_stars = $2, github_forks = $3, \
47-
github_issues = $4, github_last_commit = $5, \
48-
github_last_update = NOW() WHERE id = $6",
45+
conn.execute("UPDATE crates
46+
SET github_description = $1,
47+
github_stars = $2, github_forks = $3,
48+
github_issues = $4, github_last_commit = $5,
49+
github_last_update = NOW() WHERE id = $6",
4950
&[&fields.description,
5051
&(fields.stars as i32),
5152
&(fields.forks as i32),

0 commit comments

Comments
 (0)