Document not found (404)
+This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml new file mode 100644 index 0000000..e9fe05c --- /dev/null +++ b/.github/workflows/deploy-docs.yml @@ -0,0 +1,41 @@ +name: deploy-docs +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + contents: write # To push a branch + pull-requests: write # To create a PR from that branch + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Install latest mdbook + run: | + tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name') + url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz" + mkdir mdbook + curl -sSL $url | tar -xz --directory=./mdbook + echo `pwd`/mdbook >> $GITHUB_PATH + - name: Deploy GitHub Pages + run: | + # This assumes your book is in the root of your repository. + # Just add a `cd` here if you need to change to another directory. + cd docs + mdbook build + git worktree add gh-pages + git config user.name "Deploy from CI" + git config user.email "" + cd gh-pages + # Delete the ref to avoid keeping history. + git update-ref -d refs/heads/gh-pages + rm -rf * + mv ../book/* . + git add . + git commit -m "Deploy $GITHUB_SHA to gh-pages" + git push --force --set-upstream origin gh-pages \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..1b17878 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,65 @@ +name: publish-to-maven-central +on: workflow_dispatch + +jobs: + build: + strategy: + matrix: + os: [ macOS-latest, windows-latest, ubuntu-latest ] + runs-on: ${{matrix.os}} + steps: + - name: Checkout the repo + uses: actions/checkout@v2 + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Cache gradle + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Cache konan + uses: actions/cache@v2 + with: + path: ~/.konan + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Publish Mac Artifacts + if: matrix.os == 'macOS-latest' + run: ./gradlew publishMac --no-daemon --stacktrace + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGNING_KEYID: ${{ secrets.SIGNING_KEYID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + PUBLISHING: "true" + + - name: Publish Linux Artifacts + if: matrix.os == 'ubuntu-latest' + run: ./gradlew publishLinux --no-daemon --stacktrace + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGNING_KEYID: ${{ secrets.SIGNING_KEYID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + PUBLISHING: "true" + + - name: Publish Windows Artifacts + if: matrix.os == 'windows-latest' + run: ./gradlew publishWindows --no-daemon --stacktrace + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGNING_KEYID: ${{ secrets.SIGNING_KEYID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + PUBLISHING: "true" + + +env: + GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3g" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd96a72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ +/pocket-kt-test/* +/mkdocs +mdbook +*.http +.kotlin/* +pocketbase-executables/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +.idea/* +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/404.html b/404.html new file mode 100644 index 0000000..0851a90 --- /dev/null +++ b/404.html @@ -0,0 +1,218 @@ + + +
+ + +This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +Very seldom do users need to create a new collection with the API, but in the rare instances where this is necessary, +there are a couple of differences that should be noted.
+There is no need to create your own collection data class like with the record service, we helpfully provide one with +all the features need to create a collection.
+In this example we create the collection used in the usage example using +Pocketbase Kotlin.
+val client = PocketbaseClient({
+ protocol = URLProtocol.HTTP
+ host = "localhost"
+ port = 8090
+})
+
+client.login {
+ token = client.admins.authWithPassword("email","password").token
+}
+
+//Simply use the collection object and fill out the fields as needed
+val collection = Collection(
+ name = "people",
+ type = Collection.CollectionType.BASE,
+ schema = listOf(
+ SchemaField(
+ name = "name",
+ type = SchemaField.SchemaFieldType.TEXT,
+ required = true,
+ ),
+ SchemaField(
+ name = "age",
+ type = SchemaField.SchemaFieldType.NUMBER,
+ required = true,
+ options = SchemaField.SchemaOptions(
+ //Some options such as min and max can different types
+ //to fix this issue we serialise them as JsonPrimitives
+ min = 0.toJsonPrimitive(),
+ max = 150.toJsonPrimitive()
+ )
+ ),
+ SchemaField(
+ name = "pet",
+ type = SchemaField.SchemaFieldType.SELECT,
+ required = false,
+ options = SchemaField.SchemaOptions(
+ values = listOf("Dog","Cat","Bird")
+ )
+ )
+ )
+)
+//The generic '<Collection>' encodes our collection to JSON based on the Collection class
+client.collections.create<Collection>(Json.encodeToString(collection))
+
+
+ Due to the fact that Pocketbase Kotlin is multiplatform, file uploads do not use the Java File
class.
+There is a special utility class called FileUpload
designed specifically for this task.
+Although there are some caveats to using file uploads, as the way we handle multipart form data prevents using
+serialised records. Meaning that we must use a key value map of Json elements.
val client = PocketbaseClient({
+ protocol = URLProtocol.HTTP
+ host = "localhost"
+ port = 8090
+})
+
+client.login {
+ token = client.users.authWithPassword("email","password").token
+}
+
+///Make sure that the field for your file is a string
+//If you have multiple file uploads in your schema make it a list of strings
+@Serializable
+data class FileUploadRecord(val imageFile: String, val imageDescription: String) : Record()
+
+client.records.create<FileUploadRecord>(
+ "fileUploadCollection",
+ //A workaround to the limitations on JSON with multipart form data
+ mapOf(
+ "imageDescription" to "A house".toJsonPrimitive()
+ ),
+ //Here is where the files are uploaded from
+ //Swap ByteArray(0) with the file's content as a ByteArray
+ listOf(
+ FileUpload("imageFile", ByteArray(0), "house.png")
+ )
+)
+
+val client = PocketbaseClient({
+ protocol = URLProtocol.HTTP
+ host = "localhost"
+ port = 8090
+})
+
+client.login {
+ token = client.users.authWithPassword("email", "password").token
+}
+
+//For this example imagine we have two collections. One that contains users...
+@Serializable
+data class PersonRecord(val name: String) : User()
+
+//And one that contains their pets
+//Each Pet has a name (text), owner (relation), and each Person has a name (text)
+@Serializable
+data class PetRecord(val owner: String,val name: String) : ExpandRecord<PersonRecord>()
+//This example gets a list of pets, selects the first one and gets its owner
+
+val records = client.records.getList<PetRecord>("pets_collection",1,3,
+//This tells Pocketbase to expand the relation field of owner
+ expandRelations = ExpandRelations("owner"))
+
+//This returns the expanded record with the field name of owner
+val owner: PersonRecord? = records.items[0].expand?.get("owner")
+
+
+ This section is dedicated to informing users of the small quirks and irregularities between Pocketbase Kotlin and +the official Pocketbase web API.
+There is a document for each service and their irregularities and quirks.
+ +Pocketbase Kotlin offers support for Pocketbase 0.20 and above. +and above. +Support for new Pocketbase releases will be added as soon as possible.
+Currently, the following platforms are supported,
+Supported Platforms |
---|
JVM |
Linux (x64) |
Windows (x64) |
Mac OS (x64) (arm x64) |
IOS (arm x64) (x64) (sim arm x64) |
Want a platform supported? Open an issue, and we will try our +best to add it.
+Using this library requires the +KotlinX Serialization plugin
+To use Pocketbase Kotlin just add the following into your buildscript:
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ implementation("io.github.agrevster:pocketbase-kotlin:2.6.0")
+}
+
+
+