Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed order of arguments in If Statements #83

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/fauna/setup/accounts.js
Expand Up @@ -51,9 +51,9 @@ async function createAccountCollection(client) {
}

async function deleteAccountsCollection(client) {
await client.query(If(Exists(Collection('accounts')), true, Delete(Collection('accounts'))))
await client.query(If(Exists(Index('accounts_by_email')), true, Delete(Index('accounts_by_email'))))
await client.query(If(Exists(Index('all_accounts')), true, Delete(Delete('all_accounts'))))
await client.query(If(Exists(Collection('accounts')), Delete(Collection('accounts')), true))
await client.query(If(Exists(Index('accounts_by_email')), Delete(Index('accounts_by_email')), true))
await client.query(If(Exists(Index('all_accounts')), Delete(Delete('all_accounts')), true))
}

const DeleteAllAccounts = If(
Expand Down
4 changes: 2 additions & 2 deletions src/fauna/setup/comments.js
Expand Up @@ -39,8 +39,8 @@ async function createCommentsCollection(client) {
// If you delete a collection/index you have to wait 60 secs before the
// names go out of the cache before you reuse them.
async function deleteCommentsCollection(client) {
await client.query(If(Exists(Collection('comments')), true, Delete(Collection('comments'))))
await client.query(If(Exists(Index('comments_by_fweet_ordered')), true, Delete(Index('comments_by_fweet_ordered'))))
await client.query(If(Exists(Collection('comments')), Delete(Collection('comments')), true))
await client.query(If(Exists(Index('comments_by_fweet_ordered')), Delete(Index('comments_by_fweet_ordered')), true))
}

// Example of how you could delete all comments in a collection
Expand Down
8 changes: 4 additions & 4 deletions src/fauna/setup/followerstats.js
Expand Up @@ -117,16 +117,16 @@ async function createFollowerStatsCollection(client) {
}

async function deleteFollowerStatsCollection(client) {
await client.query(If(Exists(Collection('followerstats')), true, Delete(Collection('followerstats'))))
await client.query(If(Exists(Collection('followerstats')), Delete(Collection('followerstats')), true))
await client.query(
If(
Exists(Index('followerstats_by_author_and_follower')),
true,
Delete(Index('followerstats_by_author_and_follower'))
Delete(Index('followerstats_by_author_and_follower')),
true
)
)
await client.query(
If(Exists(Index('followerstats_by_user_popularity')), true, Delete(Index('followerstats_by_user_popularity')))
If(Exists(Index('followerstats_by_user_popularity')), Delete(Index('followerstats_by_user_popularity')), true)
)
}

Expand Down
15 changes: 7 additions & 8 deletions src/fauna/setup/fweets.js
Expand Up @@ -199,19 +199,18 @@ async function createFweetsCollection(client) {
// If you delete a collection/index you have to wait 60 secs before the
// names go out of the cache before you reuse them.
async function deleteFweetsCollection(client) {
await client.query(If(Exists(Collection('fweets')), true, Delete(Collection('fweets'))))
await client.query(If(Exists(Index('all_fweets')), true, Delete(Index('all_fweets'))))
await client.query(If(Exists(Index('fweets_by_author')), true, Delete(Index('fweets_by_author'))))
await client.query(If(Exists(Index('fweets_by_tag')), true, Delete(Index('fweets_by_tag'))))
await client.query(If(Exists(Index('fweets_by_reference')), true, Delete(Index('fweets_by_reference'))))
await client.query(If(Exists(Index('fweets_by_hashtag_ref')), true, Delete(Index('fweets_by_hashtag_ref'))))
await client.query(If(Exists(Collection('fweets')), Delete(Collection('fweets')), true))
await client.query(If(Exists(Index('all_fweets')), Delete(Index('all_fweets')), true))
await client.query(If(Exists(Index('fweets_by_author')), Delete(Index('fweets_by_author')), true))
await client.query(If(Exists(Index('fweets_by_tag')), Delete(Index('fweets_by_tag')), true))
await client.query(If(Exists(Index('fweets_by_reference')), Delete(Index('fweets_by_reference')), true))
await client.query(If(Exists(Index('fweets_by_hashtag_ref')), Delete(Index('fweets_by_hashtag_ref')), true))
}

// Example of how you could delete all fweets in a collection
const DeleteAllFweets = If(
Exists(Collection('fweets')),
q.Map(Paginate(Documents(Collection('fweets'))), Lambda('ref', Delete(Var('ref')))),
true
q.Map(Paginate(Documents(Collection('fweets'))), Lambda('ref', Delete(Var('ref')), true))
)

export { createFweetsCollection, deleteFweetsCollection, DeleteAllFweets }
9 changes: 3 additions & 6 deletions src/fauna/setup/fweetstats.js
Expand Up @@ -37,16 +37,13 @@ async function createFweetStatsCollection(client) {
}

async function deleteFweetStatsCollection(client) {
await client.query(If(Exists(Collection('fweetstats')), true, Delete(Collection('fweetstats'))))
await client.query(
If(Exists(Index('fweetstats_by_user_and_fweet')), true, Delete(Index('fweetstats_by_user_and_fweet')))
)
await client.query(If(Exists(Collection('fweetstats')), Delete(Collection('fweetstats')), true))
await client.query(If(Exists(Index('fweetstats_by_user_and_fweet')), Delete(Index('fweetstats_by_user_and_fweet')), true))
}

const DeleteAllFweetStats = If(
Exists(Collection('fweetstats')),
q.Map(Paginate(Documents(Collection('fweetstats'))), Lambda('ref', Delete(Var('ref')))),
true
q.Map(Paginate(Documents(Collection('fweetstats'))), Lambda('ref', Delete(Var('ref')))), true
)

export { DeleteAllFweetStats, createFweetStatsCollection, deleteFweetStatsCollection }
7 changes: 3 additions & 4 deletions src/fauna/setup/hashtags.js
Expand Up @@ -31,14 +31,13 @@ async function createHashtagCollection(client) {
}

async function deleteHashtagCollection(client) {
await client.query(If(Exists(Collection('hashtags')), true, Delete(Collection('hashtags'))))
await client.query(If(Exists(Index('hashtags_by_name')), true, Delete(Index('hashtags_by_name'))))
await client.query(If(Exists(Collection('hashtags')), Delete(Collection('hashtags')), true))
await client.query(If(Exists(Index('hashtags_by_name')), Delete(Index('hashtags_by_name')), true))
}

const DeleteAllHashtags = If(
Exists(Collection('hashtags')),
q.Map(Paginate(Documents(Collection('hashtags'))), Lambda('ref', Delete(Var('ref')))),
true
q.Map(Paginate(Documents(Collection('hashtags'))), Lambda('ref', Delete(Var('ref')))), true
)

export { createHashtagCollection, deleteHashtagCollection, DeleteAllHashtags }
11 changes: 5 additions & 6 deletions src/fauna/setup/rate-limiting.js
Expand Up @@ -44,21 +44,20 @@ async function createRateLimitingCollection(client) {
}

async function deleteRateLimitingCollection(client) {
await client.query(If(Exists(Collection('rate_limiting')), true, Delete(Collection('rate_limiting'))))
await client.query(If(Exists(Index('all_rate_limiting')), true, Delete(Index('all_rate_limiting'))))
await client.query(If(Exists(Collection('rate_limiting')), Delete(Collection('rate_limiting')), true))
await client.query(If(Exists(Index('all_rate_limiting')), Delete(Index('all_rate_limiting')), true))
await client.query(
If(
Exists(Index('rate_limiting_by_action_and_identity')),
true,
Delete(Index('rate_limiting_by_action_and_identity'))
Delete(Index('rate_limiting_by_action_and_identity')),
true
)
)
}

const DeleteAllRatelimiting = If(
Exists(Collection('rate_limiting')),
q.Map(Paginate(Documents(Collection('rate_limiting'))), Lambda('ref', Delete(Var('ref')))),
true
q.Map(Paginate(Documents(Collection('rate_limiting'))), Lambda('ref', Delete(Var('ref')))), true
)

export { createRateLimitingCollection, deleteRateLimitingCollection, CreateIndexAllRateLimiting, DeleteAllRatelimiting }
2 changes: 1 addition & 1 deletion src/fauna/setup/searching.js
Expand Up @@ -269,7 +269,7 @@ async function createSearchIndexes(client) {

async function deleteSearchIndexes(client) {
await client.query(
If(Exists(Index('hashtags_and_users_by_wordparts')), true, Delete(Index('hashtags_and_users_by_wordparts')))
If(Exists(Index('hashtags_and_users_by_wordparts')), Delete(Index('hashtags_and_users_by_wordparts')), true)
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/fauna/setup/users.js
Expand Up @@ -54,15 +54,15 @@ async function createUsersCollection(client) {

async function deleteUsersCollection(client) {
await handlePromiseError(
client.query(If(Exists(Collection('users')), true, Delete(Collection('users')))),
client.query(If(Exists(Collection('users')), Delete(Collection('users')), true)),
'Delete users collection'
)
await handlePromiseError(
client.query(If(Exists(Index('users_by_alias')), true, Delete(Index('users_by_alias')))),
client.query(If(Exists(Index('users_by_alias')), Delete(Index('users_by_alias')), true)),
'Delete users_by_alias index'
)
await handlePromiseError(
client.query(If(Exists(Index('all_users')), true, Delete(Index('all_users')))),
client.query(If(Exists(Index('all_users')), Delete(Index('all_users')), true)),
'Delete all_users index'
)
}
Expand Down