dolphins7.skeleton/twenty-server/lib/twenty-server.rb

38 lines
797 B
Ruby
Raw Normal View History

2023-12-08 17:28:45 +01:00
# frozen_string_literal: true
2023-12-08 17:28:45 +01:00
module Twenty
require "fileutils"
2024-03-28 06:22:08 +01:00
require "sequel"
require_relative "twenty-server/path"
2024-01-07 09:51:08 +01:00
##
# @return [String]
2024-01-28 03:49:40 +01:00
# Returns the location of the default SQLite database.
def self.default_database
2024-03-28 18:02:07 +01:00
@default_database ||= File.join(Path.datadir, "database.sqlite")
end
##
# Establishes a database connection.
#
# @param [String] path
# The path to a SQLite3 database file.
#
# @return [void]
def self.establish_connection(path:)
2024-03-28 06:22:08 +01:00
@connection = Sequel.connect(
adapter: "sqlite",
database: path
)
end
2024-03-28 06:22:08 +01:00
def self.connection
establish_connection unless @connection
@connection
end
2024-03-28 18:02:07 +01:00
FileUtils.touch(default_database)
2024-03-28 06:22:08 +01:00
require_relative "twenty-server/graphql"
require_relative "twenty-server/rack"
2023-12-08 17:28:45 +01:00
end