Skip to content

Commit 63edbf0

Browse files
committed
renamed to gmsv_async_postgres
1 parent dddd882 commit 63edbf0

File tree

10 files changed

+54
-49
lines changed

10 files changed

+54
-49
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ if(NOT DEFINED GIT_BRANCH)
3333
)
3434
endif()
3535

36-
project(gm_pgsqloo
36+
project(gmsv_async_postgres
3737
VERSION 1.0.0
3838
LANGUAGES C CXX
39-
HOMEPAGE_URL "https://github.com/Pika-Software/gm_pgsqloo"
39+
HOMEPAGE_URL "https://github.com/Pika-Software/gmsv_async_postgres"
4040
)
4141

4242
# Enable -fPIC flag

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# gm_pgsqloo
1+
# async_postgres
22
PostgreSQL binary module for Garry's Mod

source/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ configure_file(config.hpp.in ${CMAKE_BINARY_DIR}/include/config.hpp)
44
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.cpp *.hpp)
55
source_group(TREE ${CMAKE_CURRENT_LIST_DIR} PREFIX "Sources" FILES ${SOURCES})
66

7-
add_library(pgsqloo SHARED ${SOURCES})
7+
add_library(async_postgres SHARED ${SOURCES})
88

9-
target_link_libraries(pgsqloo PRIVATE
9+
target_link_libraries(async_postgres PRIVATE
1010
gmod::common
1111
gmod::helpers
1212
PostgreSQL::PostgreSQL
1313
)
1414

15-
target_include_directories(pgsqloo PRIVATE
15+
target_include_directories(async_postgres PRIVATE
1616
${CMAKE_CURRENT_LIST_DIR}
1717
${CMAKE_BINARY_DIR}/include
1818
)
1919

20-
set_gmod_suffix_prefix(pgsqloo)
20+
set_gmod_suffix_prefix(async_postgres)
2121

2222
# Autoinstall
2323
set(AUTOINSTALL "" CACHE PATH "Autoinstall path")
2424
if(IS_DIRECTORY ${AUTOINSTALL})
25-
autoinstall(pgsqloo ${AUTOINSTALL})
25+
autoinstall(async_postgres ${AUTOINSTALL})
2626
endif()

source/pgsqloo.hpp renamed to source/async_postgres.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace GLua = GarrysMod::Lua;
3636
} \
3737
int name##__Imp([[maybe_unused]] GarrysMod::Lua::ILuaInterface* lua)
3838

39-
namespace pgsqloo {
39+
namespace async_postgres {
4040
struct SocketStatus {
4141
bool read_ready = false;
4242
bool write_ready = false;
@@ -85,4 +85,4 @@ namespace pgsqloo {
8585
std::string_view get_string(GLua::ILuaInterface* lua, int index = -1);
8686
void pcall(GLua::ILuaInterface* lua, int nargs, int nresults);
8787
SocketStatus check_socket_status(PGconn* conn);
88-
}; // namespace pgsqloo
88+
}; // namespace async_postgres

source/connection.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "pgsqloo.hpp"
1+
#include "async_postgres.hpp"
22

3-
using namespace pgsqloo;
3+
using namespace async_postgres;
44

5-
std::vector<Connection*> pgsqloo::connections = {};
5+
std::vector<Connection*> async_postgres::connections = {};
66

77
struct ConnectionEvent {
88
PGconnPtr conn;
@@ -23,8 +23,8 @@ inline bool socket_is_ready(PGconn* conn, PostgresPollingStatusType status) {
2323
return true;
2424
}
2525

26-
void pgsqloo::connect(GLua::ILuaInterface* lua, std::string_view url,
27-
GLua::AutoReference&& callback) {
26+
void async_postgres::connect(GLua::ILuaInterface* lua, std::string_view url,
27+
GLua::AutoReference&& callback) {
2828
auto conn = PGconnPtr(PQconnectStart(url.data()), &PQfinish);
2929
auto conn_ptr = conn.get();
3030

@@ -84,7 +84,7 @@ inline bool poll_pending_connection(GLua::ILuaInterface* lua,
8484
return false;
8585
}
8686

87-
void pgsqloo::process_pending_connections(GLua::ILuaInterface* lua) {
87+
void async_postgres::process_pending_connections(GLua::ILuaInterface* lua) {
8888
for (auto it = pending_connections.begin();
8989
it != pending_connections.end();) {
9090
auto& event = *it;

source/main.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#include <GarrysMod/Lua/Interface.h>
22

3-
#include "pgsqloo.hpp"
3+
#include "async_postgres.hpp"
44

5-
int pgsqloo::connection_meta = 0;
5+
int async_postgres::connection_meta = 0;
66

7-
#define lua_connection_state() \
8-
lua->GetUserType<pgsqloo::Connection>(1, pgsqloo::connection_meta)
7+
#define lua_connection_state() \
8+
lua->GetUserType<async_postgres::Connection>( \
9+
1, async_postgres::connection_meta)
910

1011
lua_protected_fn(gc_connection) {
1112
delete lua_connection_state();
1213
return 0;
1314
}
1415

15-
pgsqloo::Connection::~Connection() {
16+
async_postgres::Connection::~Connection() {
1617
// remove connection from global list
1718
// so event loop doesn't try to process it
18-
pgsqloo::connections.erase(std::find(pgsqloo::connections.begin(),
19-
pgsqloo::connections.end(), this));
19+
async_postgres::connections.erase(
20+
std::find(async_postgres::connections.begin(),
21+
async_postgres::connections.end(), this));
2022
}
2123

2224
lua_protected_fn(index_connection) {
@@ -31,7 +33,7 @@ lua_protected_fn(index_connection) {
3133

3234
// is it alright if I don't pop previous stack values?
3335

34-
lua->PushMetaTable(pgsqloo::connection_meta);
36+
lua->PushMetaTable(async_postgres::connection_meta);
3537
lua->Push(2);
3638
lua->GetTable(-2);
3739

@@ -172,11 +174,11 @@ lua_protected_fn(newindex_connection) {
172174
// }
173175

174176
lua_protected_fn(loop) {
175-
pgsqloo::process_pending_connections(lua);
177+
async_postgres::process_pending_connections(lua);
176178

177-
for (auto state : pgsqloo::connections) {
178-
pgsqloo::process_notifications(lua, state);
179-
pgsqloo::process_queries(lua, state);
179+
for (auto state : async_postgres::connections) {
180+
async_postgres::process_notifications(lua, state);
181+
async_postgres::process_queries(lua, state);
180182
}
181183

182184
return 0;
@@ -189,20 +191,20 @@ lua_protected_fn(connect) {
189191
auto url = lua->GetString(1);
190192
GLua::AutoReference callback(lua, 2);
191193

192-
pgsqloo::connect(lua, url, std::move(callback));
194+
async_postgres::connect(lua, url, std::move(callback));
193195

194196
return 0;
195197
}
196198

197199
lua_protected_fn(query) {
198-
lua->CheckType(1, pgsqloo::connection_meta);
200+
lua->CheckType(1, async_postgres::connection_meta);
199201
lua->CheckType(2, GLua::Type::String);
200202
lua->CheckType(3, GLua::Type::Function);
201203

202204
auto state = lua_connection_state();
203205

204-
pgsqloo::SimpleCommand command = {lua->GetString(2)};
205-
pgsqloo::Query query = {std::move(command)};
206+
async_postgres::SimpleCommand command = {lua->GetString(2)};
207+
async_postgres::Query query = {std::move(command)};
206208
if (!lua->IsType(3, GLua::Type::Nil)) {
207209
query.callback = GLua::AutoReference(lua, 3);
208210
}
@@ -232,7 +234,7 @@ lua_protected_fn(query) {
232234
// }
233235

234236
inline void register_connection_mt(GLua::ILuaInterface* lua) {
235-
pgsqloo::connection_meta = lua->CreateMetaTable("PGconn");
237+
async_postgres::connection_meta = lua->CreateMetaTable("PGconn");
236238

237239
lua->PushCFunction(index_connection);
238240
lua->SetField(-2, "__index");
@@ -255,14 +257,14 @@ inline void make_global_table(GLua::ILuaInterface* lua) {
255257
lua->PushCFunction(connect);
256258
lua->SetField(-2, "connect");
257259

258-
lua->SetField(GLua::INDEX_GLOBAL, "pg");
260+
lua->SetField(GLua::INDEX_GLOBAL, "async_postgres");
259261
}
260262

261263
inline void register_loop_hook(GLua::ILuaInterface* lua) {
262264
lua->GetField(GLua::INDEX_GLOBAL, "hook");
263265
lua->GetField(-1, "Add");
264266
lua->PushString("Think");
265-
lua->PushString("pg_loop");
267+
lua->PushString("async_postgres_loop");
266268
lua->PushCFunction(loop);
267269
lua->Call(3, 0);
268270
lua->Pop();

source/notifications.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "pgsqloo.hpp"
1+
#include "async_postgres.hpp"
22

3-
using namespace pgsqloo;
3+
using namespace async_postgres;
44

55
bool push_on_notify(GLua::ILuaInterface* lua, Connection* state) {
66
state->lua_table.Push();
@@ -14,8 +14,8 @@ bool push_on_notify(GLua::ILuaInterface* lua, Connection* state) {
1414
return true;
1515
}
1616

17-
void pgsqloo::process_notifications(GLua::ILuaInterface* lua,
18-
Connection* state) {
17+
void async_postgres::process_notifications(GLua::ILuaInterface* lua,
18+
Connection* state) {
1919
if (!push_on_notify(lua, state)) {
2020
return;
2121
}

source/query.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "pgsqloo.hpp"
1+
#include "async_postgres.hpp"
22

3-
using namespace pgsqloo;
3+
using namespace async_postgres;
44

55
// returns true if query was sent
66
// returns false on error
@@ -47,7 +47,8 @@ bool bad_result(PGresult* result) {
4747
status == PGRES_FATAL_ERROR;
4848
}
4949

50-
void pgsqloo::process_queries(GLua::ILuaInterface* lua, Connection* state) {
50+
void async_postgres::process_queries(GLua::ILuaInterface* lua,
51+
Connection* state) {
5152
if (state->queries.empty()) {
5253
// no queries to process
5354
return;

source/result.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#include <tuple>
22
#include <vector>
33

4-
#include "pgsqloo.hpp"
4+
#include "async_postgres.hpp"
55

66
struct FieldInfo {
77
const char* name;
88
bool text;
99
Oid type;
1010
};
1111

12-
void pgsqloo::create_result_table(GLua::ILuaInterface* lua, PGresult* result) {
12+
void async_postgres::create_result_table(GLua::ILuaInterface* lua,
13+
PGresult* result) {
1314
lua->CreateTable();
1415

1516
std::vector<FieldInfo> fields;

source/util.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include <Platform.hpp>
22
#include <format>
33

4-
#include "pgsqloo.hpp"
4+
#include "async_postgres.hpp"
55

6-
using namespace pgsqloo;
6+
using namespace async_postgres;
77

8-
std::string_view pgsqloo::get_string(GLua::ILuaInterface* lua, int index) {
8+
std::string_view async_postgres::get_string(GLua::ILuaInterface* lua,
9+
int index) {
910
unsigned int len = 0;
1011
const char* str = lua->GetString(index, &len);
1112
return {str, len};
@@ -23,7 +24,7 @@ void print_stack(GLua::ILuaInterface* lua) {
2324
}
2425
}
2526

26-
void pgsqloo::pcall(GLua::ILuaInterface* lua, int nargs, int nresults) {
27+
void async_postgres::pcall(GLua::ILuaInterface* lua, int nargs, int nresults) {
2728
lua->GetField(GLua::INDEX_GLOBAL, "ErrorNoHaltWithStack");
2829
lua->Insert(-nargs - 2);
2930
if (lua->PCall(nargs, nresults, -nargs - 2) != 0) {
@@ -40,7 +41,7 @@ void pgsqloo::pcall(GLua::ILuaInterface* lua, int nargs, int nresults) {
4041
#include <poll.h>
4142
#endif
4243

43-
SocketStatus pgsqloo::check_socket_status(PGconn* conn) {
44+
SocketStatus async_postgres::check_socket_status(PGconn* conn) {
4445
SocketStatus status = {};
4546
int fd = PQsocket(conn);
4647
if (fd < 0) {

0 commit comments

Comments
 (0)