forked from elixir-sqlite/exqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 12cfdf9
Showing
21 changed files
with
247,706 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
Language: Cpp | ||
AccessModifierOffset: -2 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: true | ||
AlignConsecutiveDeclarations: false | ||
AlignConsecutiveMacros: true | ||
AlignEscapedNewlinesLeft: false | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: false | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: TopLevel | ||
AlwaysBreakAfterReturnType: TopLevelDefinitions | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: true | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
BraceWrapping: | ||
AfterClass: true | ||
AfterControlStatement: false | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: false | ||
AfterObjCDeclaration: false | ||
AfterStruct: true | ||
AfterUnion: true | ||
BeforeCatch: false | ||
BeforeElse: false | ||
IndentBraces: false | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Mozilla | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: true | ||
ColumnLimit: 0 | ||
CommentPragmas: '^ IWYU pragma:' | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth: 2 | ||
ContinuationIndentWidth: 2 | ||
Cpp11BracedListStyle: true | ||
DerivePointerAlignment: false | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] | ||
IncludeCategories: | ||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' | ||
Priority: 2 | ||
- Regex: '^(<|"(gtest|isl|json)/)' | ||
Priority: 3 | ||
- Regex: '.*' | ||
Priority: 1 | ||
IndentCaseLabels: true | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
IndentPPDirectives: BeforeHash | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCBlockIndentWidth: 2 | ||
ObjCSpaceAfterProperty: true | ||
ObjCSpaceBeforeProtocolList: false | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 200 | ||
PointerAlignment: Left | ||
ReflowComments: false | ||
SortIncludes: false | ||
SpaceAfterCStyleCast: false | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Cpp11 | ||
TabWidth: 4 | ||
UseTab: Never | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
line_length: 88 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
exqlite-*.tar | ||
|
||
|
||
# Temporary files for e.g. tests | ||
/tmp | ||
|
||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Matthew A. Johnston | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
SRC = sqlite3/sqlite3.c c_src/sqlite3_nif.c | ||
|
||
CFLAGS ?= -g | ||
|
||
# TODO: We should allow the person building to be able to specify this | ||
CFLAGS += -O3 | ||
|
||
CFLAGS += -Wall | ||
CFLAGS += -I"$(ERTS_INCLUDE_DIR)" | ||
CFLAGS += -Isqlite3 -Ic_src | ||
CFLAGS += -DSQLITE_THREADSAFE=1 -DSQLITE_USE_URI -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS | ||
|
||
# TODO: We should allow the person building to be able to specify this | ||
CFLAGS += -DNDEBUG=1 | ||
|
||
KERNEL_NAME := $(shell uname -s) | ||
|
||
PRIV_DIR = $(MIX_APP_PATH)/priv | ||
LIB_NAME = $(PRIV_DIR)/sqlite3_nif.so | ||
|
||
ifneq ($(CROSSCOMPILE),) | ||
LIB_CFLAGS := -shared -fPIC -fvisibility=hidden | ||
SO_LDFLAGS := -Wl,-soname,libsqlite3.so.0 | ||
else | ||
ifeq ($(KERNEL_NAME), Linux) | ||
LIB_CFLAGS := -shared -fPIC -fvisibility=hidden | ||
SO_LDFLAGS := -Wl,-soname,libsqlite3.so.0 | ||
endif | ||
ifeq ($(KERNEL_NAME), Darwin) | ||
LIB_CFLAGS := -dynamiclib -undefined dynamic_lookup | ||
endif | ||
ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD NetBSD)) | ||
LIB_CFLAGS := -shared -fPIC | ||
endif | ||
endif | ||
|
||
all: $(PRIV_DIR) $(LIB_NAME) | ||
|
||
$(LIB_NAME): $(SRC) | ||
$(CC) $(CFLAGS) $(LIB_CFLAGS) $(SO_LDFLAGS) $^ -o $@ | ||
|
||
$(PRIV_DIR): | ||
mkdir -p $@ | ||
|
||
clean: | ||
rm -f $(LIB_NAME) | ||
|
||
.PHONY: all clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
!IF [where /Q Makefile.auto.win] | ||
# The file doesn't exist, so don't include it. | ||
!ELSE | ||
!INCLUDE Makefile.auto.win | ||
!IF [del /Q /F Makefile.auto.win] == 0 | ||
!ENDIF | ||
!ENDIF | ||
|
||
NMAKE = nmake /$(MAKEFLAGS) | ||
CFLAGS = /O2 /EHsc /I"sqlite3" | ||
|
||
SRC = sqlite3\sqlite3.c c_src\sqlite3_nif.c c_src\queue.c | ||
|
||
all: clean priv\sqlite3_nif.dll | ||
|
||
clean: | ||
del /Q /F priv | ||
|
||
Makefile.auto.win: | ||
erl -noshell -s init stop -eval "io:setopts(standard_io, [{encoding, unicode}]), io:format(\"ERTS_INCLUDE_PATH=~ts/erts-~ts/include/\", [code:root_dir(), erlang:system_info(version)])." > $@ | ||
|
||
!IFDEF ERTS_INCLUDE_PATH | ||
priv\sqlite3_nif.dll: | ||
if NOT EXIST "priv" mkdir "priv" | ||
$(CC) $(CFLAGS) /I"$(ERTS_INCLUDE_PATH)" /LD /MD /Fe$@ $(SRC) | ||
!ELSE | ||
priv\sqlite3_nif.dll: Makefile.auto.win | ||
$(NMAKE) /F Makefile.win priv\sqlite3_nif.dll | ||
!ENDIF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Exqlite | ||
|
||
An SQLite3 library. Similar to [esqlite][1] but there are some differences. | ||
|
||
* Prepared statements are not cached. | ||
* Prepared statements are not immutable. You must be careful when manipulating | ||
statements and binding values to statements. | ||
* All calls are run through the Dirty NIF scheduler. | ||
|
||
## Installation | ||
|
||
```elixir | ||
defp deps do | ||
{:exqlite, "~> 0.1.0"} | ||
end | ||
``` | ||
|
||
## Usage | ||
|
||
It's fairly straight forward. | ||
|
||
```elixir | ||
# We'll just keep it in memory right now | ||
{:ok, conn} = Exqlite.Sqlite3.open(":memory:") | ||
|
||
# Create the table | ||
:ok = Exqlite.Sqlite3.execute(conn, "create table test (id integer primary key, stuff text)"); | ||
|
||
# Prepare a statement | ||
{:ok, statement} = Exqlite.Sqlite3.prepare(conn, "insert into test (stuff) values (?1)") | ||
:ok = Exqlite.Sqlite3.bind(conn, statement, ["Hello world"]) | ||
|
||
# Step is used to run statements | ||
:done = Exqlite.Sqlite3.step(conn, statement) | ||
|
||
# Prepare a select statement | ||
{:ok, statement} = Exqlite.Sqlite3.prepare(conn, "select id, stuff from test"); | ||
|
||
# Get the results | ||
{:row, [1, "Hello world"]} = Exqlite.Sqlite3.step(conn, statement) | ||
|
||
# No more results | ||
:done = Exqlite.Sqlite3.step(conn, statement) | ||
``` | ||
|
||
## TODO | ||
|
||
- [ ] An Ecto adapter | ||
|
||
## Under The Hood | ||
|
||
We are using the Dirty NIF scheduler to execute the sqlite calls. The rationale | ||
behind this is that maintaining each sqlite's connection command pool is | ||
complicated and error prone. | ||
|
||
## Contributing | ||
|
||
Feel free to check the project out and submit pull requests. | ||
|
||
[1]: <https://github.com/mmzeeman/esqlite> |
Empty file.
Oops, something went wrong.