header.banner.textheader.banner.link

switcore.postgres.sections.quickstart.title

switcore.postgres.sections.quickstart.description

switcore.postgres.sections.quickstart.seeInstallation switcore.instalare.badge.

💻 switcore.postgres.sections.usage.title

switcore.postgres.sections.usage.fromLua.title

switcore.postgres.sections.usage.fromLua.examples.simpleQuery.title

-- Obține datele unui jucător
local result = exports.postgres:query(
    'SELECT * FROM players WHERE id = $1', 
    {playerId}
)
if result and result.rows and result.rows[1] then
    print('Jucător: ' .. result.rows[1].name)
end

switcore.postgres.sections.usage.fromLua.examples.getOneRow.title

local user = exports.postgres:queryOne(
    'SELECT * FROM users WHERE id = $1', 
    {userId}
)

switcore.postgres.sections.usage.fromLua.examples.insert.title

local newPlayer = exports.postgres:insert('players', {
    name = 'Ion Popescu',
    money = 5000
})
print('ID jucător nou: ' .. newPlayer.id)

switcore.postgres.sections.usage.fromLua.examples.update.title

local updated = exports.postgres:update('players', {
    money = 10000
}, 'id = $1', {playerId})

switcore.postgres.sections.usage.fromLua.examples.transaction.title

exports.postgres:transaction(function(client)
    client.query('UPDATE players SET money = money - 100 WHERE id = 1')
    client.query('UPDATE players SET money = money + 100 WHERE id = 2')
end)

switcore.postgres.sections.usage.fromLua.examples.transaction.note

switcore.postgres.sections.usage.fromNode.title

const postgres = exports.postgres;

// Async/await syntax
const result = await postgres.query(
    'SELECT * FROM users WHERE id = $1', 
    [userId]
);
const user = await postgres.queryOne(
    'SELECT * FROM users WHERE id = $1', 
    [userId]
);
const users = await postgres.queryAll('SELECT * FROM users');

const newUser = await postgres.insert('users', {
    name: 'Ion',
    email: 'ion@example.com'
});

const updated = await postgres.update(
    'users', 
    { name: 'Maria' }, 
    'id = $1', 
    [userId]
);

const deleted = await postgres.delete(
    'users', 
    'id = $1', 
    [userId]
);

📚 switcore.postgres.sections.api.title

switcore.postgres.sections.api.methods.query.name

switcore.postgres.sections.api.methods.query.description

local result = exports.postgres:query(
    'SELECT * FROM players WHERE id = $1', 
    {5}
)
print(result.rowCount)  -- numărul de rânduri
print(result.rows[1].name)  -- primul rând

Returnează: switcore.postgres.sections.api.methods.query.returns

switcore.postgres.sections.api.methods.queryOne.name

switcore.postgres.sections.api.methods.queryOne.description

local player = exports.postgres:queryOne(
    'SELECT * FROM players WHERE id = $1', 
    {5}
)

Returnează: switcore.postgres.sections.api.methods.queryOne.returns

switcore.postgres.sections.api.methods.queryAll.name

switcore.postgres.sections.api.methods.queryAll.description

local players = exports.postgres:queryAll('SELECT * FROM players')

Returnează: switcore.postgres.sections.api.methods.queryAll.returns

switcore.postgres.sections.api.methods.insert.name

switcore.postgres.sections.api.methods.insert.description

local newPlayer = exports.postgres:insert('players', {
    name = 'Ion',
    money = 1000
})
print('ID: ' .. newPlayer.id)

Returnează: switcore.postgres.sections.api.methods.insert.returns

switcore.postgres.sections.api.methods.update.name

switcore.postgres.sections.api.methods.update.description

local updated = exports.postgres:update('players', {
    money = 5000
}, 'id = $1', {1})

Returnează: switcore.postgres.sections.api.methods.update.returns

switcore.postgres.sections.api.methods.delete.name

switcore.postgres.sections.api.methods.delete.description

local deleted = exports.postgres:delete(
    'players', 
    'id = $1', 
    {999}
)
print('Au fost șterse ' .. deleted .. ' rânduri')

Returnează: switcore.postgres.sections.api.methods.delete.returns

switcore.postgres.sections.api.methods.transaction.name

switcore.postgres.sections.api.methods.transaction.description

exports.postgres:transaction(function(client)
    client.query('UPDATE players SET money = money - 100 WHERE id = 1')
    client.query('UPDATE players SET money = money + 100 WHERE id = 2')
end)

Important: switcore.postgres.sections.api.methods.transaction.note

switcore.postgres.sections.api.methods.isReady.name

switcore.postgres.sections.api.methods.isReady.description

if exports.postgres:isReady() then
    print('Baza de date este gata!')
end

🔒 switcore.postgres.sections.security.title

switcore.postgres.sections.security.sqlInjection.title

switcore.postgres.sections.security.sqlInjection.description

switcore.postgres.sections.security.sqlInjection.wrong

local query = "SELECT * FROM players WHERE name = '" .. playerName .. "'"

switcore.postgres.sections.security.sqlInjection.correct

local result = exports.postgres:query('SELECT * FROM players WHERE name = $1', {playerName})

📁 switcore.postgres.sections.security.configFiles.title

  • config.local.js - switcore.postgres.sections.security.configFiles.local
  • config.local.js.example - switcore.postgres.sections.security.configFiles.example

⚠️ switcore.postgres.sections.security.configFiles.warning

🐛 switcore.postgres.sections.troubleshooting.title

switcore.postgres.sections.troubleshooting.errors.depsNotInstalled.title

Soluție: switcore.postgres.sections.troubleshooting.errors.depsNotInstalled.solution

switcore.postgres.sections.troubleshooting.errors.dbConnectionFailed.title

Verifică: switcore.postgres.sections.troubleshooting.errors.dbConnectionFailed.check

switcore.postgres.sections.troubleshooting.errors.configMissing.title

Soluție: switcore.postgres.sections.troubleshooting.errors.configMissing.solution