Skip to content

Commit

Permalink
remove unecessary ; from postgres schema functions
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Feb 2, 2021
1 parent 3071e59 commit 3daf5a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
5 changes: 2 additions & 3 deletions lapis/db/postgres/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ create_table = function(name, columns, opts)
if #columns > 0 then
add("\n")
end
add(");")
add(")")
return db.query(concat(buffer))
end
local create_index
Expand Down Expand Up @@ -129,7 +129,6 @@ create_index = function(tname, ...)
if options.when then
error("did you mean create_index `where`?")
end
append_all(buffer, ";")
return db.query(concat(buffer))
end
local drop_index
Expand All @@ -148,7 +147,7 @@ drop_index = function(...)
end
local drop_table
drop_table = function(tname)
return db.query("DROP TABLE IF EXISTS " .. tostring(escape_identifier(tname)) .. ";")
return db.query("DROP TABLE IF EXISTS " .. tostring(escape_identifier(tname)))
end
local add_column
add_column = function(tname, col_name, col_type)
Expand Down
5 changes: 2 additions & 3 deletions lapis/db/postgres/schema.moon
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ create_table = (name, columns, opts={}) ->

add "\n" if #columns > 0

add ");"
add ")"
db.query concat buffer

create_index = (tname, ...) ->
Expand Down Expand Up @@ -86,7 +86,6 @@ create_index = (tname, ...) ->
if options.when
error "did you mean create_index `where`?"

append_all buffer, ";"
db.query concat buffer

drop_index = (...) ->
Expand All @@ -101,7 +100,7 @@ drop_index = (...) ->
db.query concat buffer

drop_table = (tname) ->
db.query "DROP TABLE IF EXISTS #{escape_identifier tname};"
db.query "DROP TABLE IF EXISTS #{escape_identifier tname}"

add_column = (tname, col_name, col_type) ->
tname = escape_identifier tname
Expand Down
22 changes: 11 additions & 11 deletions spec/postgres_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ tests = {
"password_reset_token" character varying(255),
"data" text NOT NULL,
PRIMARY KEY (user_id)
);]]
)]]
}

{
Expand All @@ -301,53 +301,53 @@ tests = {
[[CREATE TABLE IF NOT EXISTS "join_stuff" (
"hello_id" integer NOT NULL,
"world_id" integer NOT NULL
);]]
)]]
}


{
-> schema.drop_table "user_data"
[[DROP TABLE IF EXISTS "user_data";]]
[[DROP TABLE IF EXISTS "user_data"]]
}

{
-> schema.create_index "user_data", "thing"
[[CREATE INDEX "user_data_thing_idx" ON "user_data" ("thing");]]
[[CREATE INDEX "user_data_thing_idx" ON "user_data" ("thing")]]
}

{
-> schema.create_index "user_data", "thing", unique: true
[[CREATE UNIQUE INDEX "user_data_thing_idx" ON "user_data" ("thing");]]
[[CREATE UNIQUE INDEX "user_data_thing_idx" ON "user_data" ("thing")]]
}

{
-> schema.create_index "user_data", "thing", unique: true, index_name: "good_idx"
[[CREATE UNIQUE INDEX "good_idx" ON "user_data" ("thing");]]
[[CREATE UNIQUE INDEX "good_idx" ON "user_data" ("thing")]]
}

{
-> schema.create_index "user_data", "thing", if_not_exists: true
[[CREATE INDEX IF NOT EXISTS "user_data_thing_idx" ON "user_data" ("thing");]]
[[CREATE INDEX IF NOT EXISTS "user_data_thing_idx" ON "user_data" ("thing")]]
}

{
-> schema.create_index "user_data", "thing", unique: true, where: "age > 100"
[[CREATE UNIQUE INDEX "user_data_thing_idx" ON "user_data" ("thing") WHERE age > 100;]]
[[CREATE UNIQUE INDEX "user_data_thing_idx" ON "user_data" ("thing") WHERE age > 100]]
}

{
-> schema.create_index "users", "friend_id", tablespace: "farket"
[[CREATE INDEX "users_friend_id_idx" ON "users" ("friend_id") TABLESPACE "farket";]]
[[CREATE INDEX "users_friend_id_idx" ON "users" ("friend_id") TABLESPACE "farket"]]
}

{
-> schema.create_index "user_data", "one", "two"
[[CREATE INDEX "user_data_one_two_idx" ON "user_data" ("one", "two");]]
[[CREATE INDEX "user_data_one_two_idx" ON "user_data" ("one", "two")]]
}

{
-> schema.create_index "user_data", db.raw("lower(name)"), "height"
[[CREATE INDEX "user_data_lower_name_height_idx" ON "user_data" (lower(name), "height");]]
[[CREATE INDEX "user_data_lower_name_height_idx" ON "user_data" (lower(name), "height")]]
}

{
Expand Down

0 comments on commit 3daf5a9

Please sign in to comment.